When you start to develop PowerShell modules it is relative easy. Just add a folder under
(Split-path $profile) + '\Modules'
say MyMod.
Then put a file MyMod.psm1 into it
Write-host "mymod loaded"
When you type ipmo Mymod, which is the alias for Import-Module you get
mymod loaded
With rmo Mymod , which is the short for Remove-Module you get rid of your module.
To check that it is removed, you can type
gmo or gmo Mymod, which is the alias for Get-Module
Now you shouldn't see it anymore.
Here I'm not going to tell you, what to put into your module file.
Best link for this I know is this post from Bruce Payette.
My focus here is, how to organise your system, when you have written something usefull and uploaded your module to some project.
I guess that you checkout your module from the project to some place, which is not in your modules folders. To ckeck where your system searches for modules just type
$env:PSModulePath -split ';'
Next I tried to be clever. I put the following into my profile:
$env:PSModulePath += ";\D:\MysharedProject\modules"
Now I can load the modules from this project by simple calles of ipmo myModule.
It really took some time to discover that I was too clever.
I'm using ISE for nearly all my PowerShell task and some time ago I discovered the menu New PowerShell Tab with the short-cut CTRL+T.
Each time you invoke this, you get a new PowerShell session and your PowerShell Profiles are executed.
But all these PowerShell session live in your current Windows session and each time the PSModulePath variable of the Windows environment will be modified. It gets longer and longer.
OK here now my final solution, this is the start of my profile.ps1
write-host "================== generall ($env:USERDOMAIN.$env:username) ==========================="
$AdditionalModulPathes = @(
"D:\someProjectBleedingEdge\Modules"
"D:\someProjectRelease\Modules"
# "D:\MyCopyOfSomeProject\Modules"
)
foreach ($path in ($AdditionalModulPathes| Get-unique) )
{
if (($env:PSModulePath -split ';') -notcontains $path)
{
$env:PSModulePath += ";" + $path
}
}
# $env:PSModulePath -split ';'
Now I modify the evironment only once.
And here is the location, where I select whether I use the stable release, the current development version or my own unpublished work.
I hope this give you some ideas.
Bernd
BTW: ISE-Cream has reached release 0.1
If you are thinking about extending ISE, take a look at it
Keine Kommentare:
Kommentar veröffentlichen