Powershell script packager

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION 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.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 10 years and 6 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
clum09
Posts: 150
Last visit: Sun Jan 21, 2024 5:07 pm

Powershell script packager

Post by clum09 »

Hello,


I have a PowerShell script that works fine when I launch it from either a command prompt using a batch file or within a the PowerShell console. The script imports the module and perform its other routines just fine within these two consoles.

I tried to package this PowerShell script using PrimalScript 2009, and I found that this script is no longer able to import the module and all other script routine fails. It complains that the mocule is not found.

I would like to know how I can package this script and have it work like it is launched within the PowerShell console.

Thank you in advance.

CluM09
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Powershell script packager

Post by Alexander Riedel »

PrimalScript 2009 is no longer subject to updates and support and does not support Powershell V3.

Modules are mostly a PowerShell V3 thing and support for that was added to the 2012 version last year when PowerShell V3 was released.

See http://www.sapien.com/blog/2012/10/22/p ... 3-support/

Also check if your modules are 64 bit only.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
clum09
Posts: 150
Last visit: Sun Jan 21, 2024 5:07 pm

Re: Powershell script packager

Post by clum09 »

Alexander,

Thank you for the response.

I am not working on the automatic module import like PowerShell V3. I can do the module import in PowerShell V2 also as long as the module is available locally on the machine. The module I am importing is the ServerManager module which is already on Windows Server 2008 R2.

When I package the script using Microsoft Windows PowerShell (Command line) mode, the packaged script works fine. The only problem I have is when I package the script with SAPIEN Powershell Host (Command line) mode. I like the fact that when I use the SAPIEN Powershell Host mode, my packaged script will run in memory without being extracted into a temp folder.

I will try to package this same script using PrimalScript 2012 and see if I still see the problem. If I still see this same problem, then I cannot use the SAPIEN Powershell Host (Command line) mode because doing so will render my packaged script unusable.

However, I don't seem to see any problem using SAPIEN Script Host (Command line) mode when I packaged my VBScript script into the self-executable file.

Thanks again.

CluM09
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Powershell script packager

Post by Alexander Riedel »

Most likely you are running your scripts from the shell in 64 bit mode.
2009 cannot package a 64 bit executable.
Can you verify what your "bitness" for the OS and your standard shell is?
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
clum09
Posts: 150
Last visit: Sun Jan 21, 2024 5:07 pm

Re: Powershell script packager

Post by clum09 »

Alexander,

PrimalScript 2009 has an option to package the script to a 64-bit version. That was what I did when I packaged the script. Otherwise, I had to turn the Execution Policy for the 32-bit in the OS in order for it to work.

Windows Server 2008 R2 is only available for 64-bit. I don't know what you meant by the bitness of the standard shell. All I know is my packaged script was packaged in a 64-bit executable file, which I can verify it as a 64-bit file.
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Powershell script packager

Post by Alexander Riedel »

Sorry, 2009 really was an eternity ago for me. :-)

Modules can fail to load for a variety or reasons. And of course a lot of changes to the engines have been made since then.
Try 2012 and let us know if you get any errors. It is possible that the module checks the host version rather than the powershell version.
It is also possible that your module requires something preset in a profile, which is not loaded in a packaged executable using the SAPIEN host.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 10 years and 6 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.