Initialize your runspace(s) with NuPack module

Oct 18, 2010 at 1:20 PM

This might help to keep things a bit tighter - you can probably get rid of your ps1 initialization script and keep everything clean in a module. Consider creating a module manifest (New-ModuleManifest) so you can isolate your init  script from your library commands (if you want.)

Here's how to ensure your Default Runspace has the NuPack module pre-loaded:

InitialSessionState initial = InitialSessionState.CreateDefault();
initialSession.ImportPSModule(new[] { "<path to nupack.psd1 or nupack.psm1>" });
Runspace runspace = RunspaceFactory.CreateRunspace(initial);
runspace.Open();
// ...

http://www.nivot.org/2010/05/03/PowerShell20DeveloperEssentials1InitializingARunspaceWithAModule.aspx

Oct 18, 2010 at 7:33 PM

We already have the cmdlets implemented in managed code and they are seperate from ps1 initialization script.

As an aside, I have tried this ImportPSModule() before. PS threw exception at runtime if the execution policy was not changed to allow execuing script. Did I miss anything? Do you know if there is a work around?