April, 11, 2018
“How to run PowerShell script from MSI in PACE Suite?” – that is the question we often recieve during our product demo. Indeed, PowerShell remains a favourite tool of system administrators because they can script alsmost any task with PowerShell (by the way, here is a handy guide on creating and editing scripts from Microsoft). As our PACE Suite helps with all the tasks associated with MSI packaging, today we decided to show how to import PowerShell script to the MSI package in our tool in order to run this script during the installation process.
Our instruction consists of two parts:
Import PowerShell script to MSI
Launch MSI Editor, a part of PACE Suite, and select Open… from MENU.
Choose an MSI package, to which you want to import the script, and click Open.
Open the Files tab.
Select Import files… from the context menu of a folder, to which you want to import the script.
Click Add -> Select files…
Choose the PowerShell script from your file system and click Open.
Now, either tick the Complete operation with default settings option or go through all the steps, choosing the necessary settings, and complete the Wizard.
Run PowerShell script from MSI via Custom Action
Open the Custom Actions tab.
Click Add -> Custom action. The Wizard that opens takes into account each option you pick and at further steps, it disables options, which are incompatible with your previous choices, so in the end you get a working Custom Action.
Select Launch an EXE and click Next.
Tick the Located on the system at the path, which is specified in the Command line field, in the selected working folder and click Browse…
Select a folder, to which you have imported the PowerShell script and click Select.
Enter the powershell.exe -ExecutionPolicy Bypass -File ““ to the Command line field, where is a name of your imported PowerShell script with the file extension (e.g. psscript.ps1). Then, click Next.
NOTE -ExecutionPolicy Bypass parameter was added to ensure the Custom Action will always execute regardless of the current execution policy on the system.
Select Deferred execution mode, Run in system context and An asynchronous execution that waits for exit code at the end of the sequence options, and click Next.
Select Run after InstallFiles (or any other position, located below this) from the Execution sequence (recommended) list, if needed, specify execution conditions either by entering them manually or choosing from the drop-down list. Click Finish to add your custom action.
Click Save from the MENU to save your MSI package.
That is how easy it is to import and run PowerShell scripts from MSI packages using PACE Suite. Try our MSI authoring tool today to see what else can you do with our smart Wizards and convenient interfaces.