Page 1 of 1

Packager, PowerShell, Snapins, oh my!

Posted: Fri Apr 23, 2010 3:04 am
by hmartin216
I'm working my way through the PrimalScript 2009 manual, so if my question is covered there, my apologies. I am trying to create .exe files of PowerShell scripts. Several of these scripts include various snapins.

The first question is about dependencies. I understand that the PC running the .exe file must have PowerShell installed, but are they also required to have the snapins installed, or can these be included in the .exe?

The second question is about performance. When I run a PowerShell script as a standard .ps1 file, it runs faster because it only has to add the snapin the first time (assuming the user leaves their command prompt open, since the script checks for the snapin before adding it). However, when running from a PrimalScript 2009 .exe of the same script, it's consistently slower because it "adds" the snapin(s) upon every execution. Is there any way to avoid this?

Thanks.

Packager, PowerShell, Snapins, oh my!

Posted: Fri Apr 23, 2010 4:46 am
by davidc
Greetings,
1. Snapins must be installed in the target computer in order for the packager's script to run correctly. The packager (by design) is not meant to install snapins.
2. You can add the Snapin in PrimalScript's profile instead of your script. Simple create a ps1 file named "PrimalScript.profile.ps1" with the Add-PSSnapin command and place it in "My DocumentsWindowsPowerShell" folder. Next time you start PrimalScript, the snapin should be loaded.

Thank you,

David

Packager, PowerShell, Snapins, oh my!

Posted: Fri Apr 23, 2010 7:48 am
by hmartin216
1. Got it. Thanks.

2. I did see this in the manual, but this is only good for my environment. So I assume that the only solution for other users to run the .exe with the best performance is to have them also include the snapins in their profile. Is that correct?

Packager, PowerShell, Snapins, oh my!

Posted: Fri Apr 23, 2010 8:17 am
by Alexander Riedel
The exe doesn't load or use any profiles in order to not create any dependencies on local settings that may no apply on another machine.
In terms of performance it wouldn't make any difference at all anyway, since each packaged EXE is its own host and loading the snapins from a profile or from within the script takes the same amount of time.

You can pre-compile powershell itself and the snapins on each machine and cache the "jitted" assemblies. There was a blog entry on the PowerShell blog about that a while ago. Without that loading PowerShell and snapins can be a bit slow.