Use this with the following component to import modules to powershell from the internet
Execute the following command in your powershell:
iex ((new-object net.webclient).DownloadString('http://psreg.net/install.ps1'));
and PsReg is installed on your machine
A module that allows to import modules and files in a more readable syntax. It ultimatly allows you to specify required Modules at the beginning of your script, and the modules will be (down-)loaded automatically.
# check the readme file for required modules to add to this module Import-Module .\PSColorWriter.psm1; # <-This fails if module not available Write-Output-Color -Red "Look " -White "I have colors"; # <- This breaks if module not available
register PSColorWriter; # <- This will download the module from the remote repository and import it Write-Output-Color -Red "Look " -White "I have colors";
If you haven't installed the component already clone the git repository, open your Powershell Profile File and add the following line:
Import-Module path_to_the_file\PSRegister.psm1 -DisableNameChecking
Then you can add a PSRegistration-Server:
You can add all known servers (which includes psreg.net) at once with the command
Once this is done you can start by trying:
register PSColorWriter Write-Output-Color -Red "Look " -White "I have colors"
Which should then print colored output
You might have a lot of components that are only on your machine and not on a PSRegistration-Server. You can add these files as well by adding a path as location. Let's try that.
If you look in the directory you can see the following subdirectories
PS>ls C:\Projects\SMP\Production\SetupTesting | select Name Name ---- Monitoring Msmq
Looking inside we can see there are files inside the directory
PS>cd .\Msmq PS>ls | select Name Name ---- msmq-tools.ps1 msmq-helpers.ps1
Since we have added the location to the PSRegistration we can add both files easily like this:
If we'd want to import only the msmq-tools file we would write
If you require a specific method of a dependency, and globally you are using another one, you can start the sandbox mode to get a clean shell. Just type
You can leave the sandbox mode by typing "powershell"
Insert a new line to the file known-locations and push request your change
Adds a new location to the registration locations if not already added
add-register-location C:\Projects\SMP\Production\SetupTesting add-register-location psregister://asdw0435:1337/
Loads all configured locations
registers a module or ps1 file
checks if a module or ps1 file is registered
All 3 stages are done every time.
Removes a location from the registered locations
add-register-location C:\Projects\SMP\Production\SetupTesting register msmq PSRegister 02/07/2014 12:27:21 script msmq-tools loaded remove-register-location C:\Projects\SMP\Production\SetupTesting
Starts a shell without profile files, but with all locations from the current PSRegistration instance
sandbox register PSColorWriter PSRegister 02/07/2014 12:26:37 module PSColorWriting loaded Write-Output-Color -Red "Alert!" > "Alert!" powershell Write-Output-Color -Red "Alert!" > The term 'Write-Output-Color' is not recognized as the name of a cmdlet, function, script file, or operable program.
Lists all available repositories
list-available-repositories > PSRegister [file:///c:/path_helpers][registered] browser-tool > PSRegister [file:///c:/path_helpers][not registered] file-replace > PSRegister [psregister://psreg.net/][not registered] How-Are-We > PSRegister [psregister://psreg.net/][registered] PSColorWriter
Cleans all temporary folders that are used for the remote repositories. Used for development