Product, version and build: PowerShell Studio 2019 version 5.6.267 (64 bit vsn)
Operating system: Windows 10 64bit
I want to run powershell scripts to make changes to a target system. I know I can bundle them in an EXE file or in an MSI file.
I know I can use the Packager to create the exe file containing my powershell script, which will execute when I double click it on the target system for the simple patches/updates.
I also want to use the MSI capability, because it allows me to create an Uninstall script for situations when I need to uninstall.
My issue: I can't seem to get a powershell script to be executed in the MSI unless I bundle it as an EXE or possibly deliver a VBS script that will execute it. Is there a way to just deliver a Powershell script that will be executed when I double click the MSI file?
I tried playing around with the Custom actions section to just add an Install Action for my powershell script, but had no luck. I am going to try adding a VBS script to the MSI file which will execute my PS1 this afternoon.
I appreciate any suggestions.
Can I get a Powershell script to execute in MSI file
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.
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.
- mxtrinidad
- Posts: 399
- Last visit: Tue May 16, 2023 6:52 am
Re: Can I get a Powershell script to execute in MSI file
Can you please provide more information on what errors are you getting?
It will help us understand what's going on wrong.
In the meantime, have you looked at the following article:
https://www.sapien.com/blog/2019/08/15/ ... xecutable/
It will help us understand what's going on wrong.
In the meantime, have you looked at the following article:
https://www.sapien.com/blog/2019/08/15/ ... xecutable/
Re: Can I get a Powershell script to execute in MSI file
No errors, my script is just not getting executed.
1. P1.ps1 script writes "hello world" to Windows Event Viewer; successfully runs in debugger
2. Create P1.msi in Powershell Studio Installer function; P1.ps1 is added to MSI via the Files/Folders tab
3. Build P1.msi in PowerShell Studio
4. Double clicking P1.msi file does NOT write "hello world" in Event Viewer
5. However, P1 does show up in the Add/Remove programs
How can I get "Hello World" to be printed by double clicking the MSI file.
1. P1.ps1 script writes "hello world" to Windows Event Viewer; successfully runs in debugger
2. Create P1.msi in Powershell Studio Installer function; P1.ps1 is added to MSI via the Files/Folders tab
3. Build P1.msi in PowerShell Studio
4. Double clicking P1.msi file does NOT write "hello world" in Event Viewer
5. However, P1 does show up in the Add/Remove programs
How can I get "Hello World" to be printed by double clicking the MSI file.
Re: Can I get a Powershell script to execute in MSI file
The blog below has a set of directions to define a different script engine in the Custom Actions field, but it does not tell you how to specify this engine.
Does anyone know how to specify Wscript.exe in Custom Actions?
https://www.sapien.com/blog/2018/02/26/ ... i-builder/
"For any other type of script you will need to specify the entire command, including what script engine you want to use (e.g., WScript.exe or JScript.exe for Windows Script Host.)
If you package your custom action scripts as executable files, you need to add the .exe file and reference that rather than the script."
Does anyone know how to specify Wscript.exe in Custom Actions?
https://www.sapien.com/blog/2018/02/26/ ... i-builder/
"For any other type of script you will need to specify the entire command, including what script engine you want to use (e.g., WScript.exe or JScript.exe for Windows Script Host.)
If you package your custom action scripts as executable files, you need to add the .exe file and reference that rather than the script."
- mxtrinidad
- Posts: 399
- Last visit: Tue May 16, 2023 6:52 am
Re: Can I get a Powershell script to execute in MSI file
If you don't want to package the PowerShell Script then you need to create a shortcut pointing to the file to execute.
MSI installer will only install the files in the system with the optional ability to use "Custom Actions" to execute additional commands during the different stages of the installer: Install, Uninstall, and Maintenance.
Before building the MSI installer, you need to create the shortcut script which will point to the location of the file to execute.
All this need to be included in the "Files and Folders" area of the MSI settings.
The blog post I pasted previously shows the steps of including a shortcut script file which could be modified to your need.
In the case of using WScript.exe and JScript.exe, you'll probably need to create a cmd line script file (*.bat, *.cmd). These files will be added to the appropriate steps in the MSI Settings.
At the end the shortcut could run the cmd line script: which could be:
PowerShell.exe c:\...\Myscripts\Script1.ps1 ...
Wscript.exe c:\...\MyScripts\Script.vbs ...
JScript.exe c:\...\MyScripts\Script3.js ...
MSI installer will only install the files in the system with the optional ability to use "Custom Actions" to execute additional commands during the different stages of the installer: Install, Uninstall, and Maintenance.
Before building the MSI installer, you need to create the shortcut script which will point to the location of the file to execute.
All this need to be included in the "Files and Folders" area of the MSI settings.
The blog post I pasted previously shows the steps of including a shortcut script file which could be modified to your need.
In the case of using WScript.exe and JScript.exe, you'll probably need to create a cmd line script file (*.bat, *.cmd). These files will be added to the appropriate steps in the MSI Settings.
At the end the shortcut could run the cmd line script: which could be:
PowerShell.exe c:\...\Myscripts\Script1.ps1 ...
Wscript.exe c:\...\MyScripts\Script.vbs ...
JScript.exe c:\...\MyScripts\Script3.js ...
Re: Can I get a Powershell script to execute in MSI file
I was under the impression that the shortcuts got added to the Start Menu which I do not want.
Can I prohibit the shortcut being added to Start Menu? I guess I could delete it in my install script, but that feels problematic.
It could be I'm thinking of an older version of the tool, as I have read a lot of blogs today.
Can I prohibit the shortcut being added to Start Menu? I guess I could delete it in my install script, but that feels problematic.
It could be I'm thinking of an older version of the tool, as I have read a lot of blogs today.
- mxtrinidad
- Posts: 399
- Last visit: Tue May 16, 2023 6:52 am
Re: Can I get a Powershell script to execute in MSI file
No need to add another script. Just select "(No Shortcut)" in the MSI "Files/Folder - Create Shortcut to" section.
This will be enough to not to create the Shortcut on the Start Menu.
This will be enough to not to create the Shortcut on the Start Menu.
- Alexander Riedel
- Posts: 8488
- Last visit: Tue Apr 16, 2024 8:42 am
- Been upvoted: 37 times
Re: Can I get a Powershell script to execute in MSI file
This thread has gotten way off track. You originally wanted to use a PowerShell Script as a custom action.
"I tried playing around with the Custom actions section to just add an Install Action for my powershell script, but had no luck."
That would be the exact location to do that. Can you elaborate on the "no luck" part? I have never seen PowerShell or MSI output a "No Luck" message box. Albeit some are close
Jokes aside, this might be helpful: https://www.sapien.com/blog/2018/02/26/ ... si-builder
It would help if you would show the configuration you have for your custom action as a screenshot.
As for using WScript, you just specify the path to WScript.exe and the script to execute in arguments. I am probably missing where the problem is, so please feel free to elaborate.
"I tried playing around with the Custom actions section to just add an Install Action for my powershell script, but had no luck."
That would be the exact location to do that. Can you elaborate on the "no luck" part? I have never seen PowerShell or MSI output a "No Luck" message box. Albeit some are close
Jokes aside, this might be helpful: https://www.sapien.com/blog/2018/02/26/ ... si-builder
It would help if you would show the configuration you have for your custom action as a screenshot.
As for using WScript, you just specify the path to WScript.exe and the script to execute in arguments. I am probably missing where the problem is, so please feel free to elaborate.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Can I get a Powershell script to execute in MSI file
I have included the trivial Hello world scripts and a screen shot of the Custom Actions screen. The other screens had no real changes. I can build the MSI file and when I double click it I don't get Hello world in the text file.
I can see my HelloWorld product in my Apps and Features, so part of it works. It just doesn't run the Install script custom action.
I can see my HelloWorld product in my Apps and Features, so part of it works. It just doesn't run the Install script custom action.
- Attachments
-
- New-WriteToLog.ps1
- Hello world in main
- (276 Bytes) Downloaded 132 times
-
- Install-WriteToLog.ps1
- Hello world in Installer
- (281 Bytes) Downloaded 158 times
-
- Add a Custom Action
- screenshot3.PNG (30.99 KiB) Viewed 4798 times
- Alexander Riedel
- Posts: 8488
- Last visit: Tue Apr 16, 2024 8:42 am
- Been upvoted: 37 times
Re: Can I get a Powershell script to execute in MSI file
Change it to deferred. Immediately will try to execute the script when the MSI is launched, at which point the script hasn't even been copied yet.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.