Packager, PowerShell, Snapins, oh my!

Use this forum to ask questions after your subscription maintenance expires or 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.
This topic is 13 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
hmartin216
Posts: 6
Last visit: Mon Dec 24, 2018 3:47 pm

Packager, PowerShell, Snapins, oh my!

Post 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.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Packager, PowerShell, Snapins, oh my!

Post 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
David
SAPIEN Technologies, Inc.
User avatar
hmartin216
Posts: 6
Last visit: Mon Dec 24, 2018 3:47 pm

Packager, PowerShell, Snapins, oh my!

Post 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?
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Packager, PowerShell, Snapins, oh my!

Post 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.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 13 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.