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";
Scripts to register can be found on PsReg.net
You can start and test the module by calling this one-liner from the command line:
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('http://psreg.net/install.ps1'))"
or directly from powershell:
iex ((new-object net.webclient).DownloadString('http://psreg.net/install.ps1'))
Otherwise clone this repo and 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 (this assumes you have one running locally)
For AutoScout24, there is a list with the known PSRegistration-Server available. You can add all known servers 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"
adding your own repository servers:
Insert a new line to the file known-locations and push request your change
List of commands
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
- Use ps1 file with this name if it exists
- Use psm1 file with this name if it exists
- Use folder with this name and load all ps1 & psm1 files in it
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://asdw0435:1337/][not registered] How-Are-We > PSRegister [psregister://asdw0435:1337/][registered] PSColorWriter
Cleans all temporary folders that are used for the remote repositories. Used for development