Packager, PowerShell, Snapins, oh my!

Use this forum to ask questions before you buy. Need information on licensing or pricing? Questions about a trial version? This is the right place for you. No scripting questions, please.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
User avatar
hmartin216
Posts: 6
Joined: Fri Apr 23, 2010 3:04 am

Packager, PowerShell, Snapins, oh my!

Post by hmartin216 » Fri Apr 23, 2010 3:04 am

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.

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Packager, PowerShell, Snapins, oh my!

Post by davidc » Fri Apr 23, 2010 4:46 am

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
David
SAPIEN Technologies, Inc.

User avatar
hmartin216
Posts: 6
Joined: Fri Apr 23, 2010 3:04 am

Packager, PowerShell, Snapins, oh my!

Post by hmartin216 » Fri Apr 23, 2010 7:48 am

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?

User avatar
Alexander Riedel
Posts: 7005
Joined: Tue May 29, 2007 4:43 pm

Packager, PowerShell, Snapins, oh my!

Post by Alexander Riedel » Fri Apr 23, 2010 8:17 am

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.
Alexander Riedel
SAPIEN Technologies, Inc.