Created
January 19, 2012 18:19
-
-
Save CalvinRodo/1641637 to your computer and use it in GitHub Desktop.
Improved Module Loading in Windows Powershell profile.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Add the profile path to the environment path variable | |
$ProfileRoot = (Split-Path -Parent $MyInvocation.MyCommand.Path) | |
$env:path = ";$ProfileRoot" | |
#Load all of the modules from ./Modules/* that aren't already loaded. | |
(gci $ProfileRoot"/Modules") | ForEach { if ( -Not( Get-Module $_.Name ) ) { Import-Module $_.Name; Write-Host Importing Module: $_.Name } } |
Pretty sure this will break existing paths, don't you mean this?
$env:path += ";$ProfileRoot"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stick this in your Powershell Profile and it will automatically load all of the modules that you've stuck in you WindowsPowerShell\Modules folder.
So for example to install the foo.dll module automaticall on powershell startup put it here:
~\My Documents\WindowsPowerShell\Modules\foo\foo.dll
Then when you next load up powershell it will be automatically imported.
Also if you .source your profile then it won't try to load modules that are already there which throws an exception.