Creating an MSI Installer for a packaged script executable

In a previous blog post we covered some of the SAPIEN Packager script engines to create an executable. Next step is to create the application installer so we can deploy the packaged solution.

We are going to take this further. We are going to reuse the “Get-SystemInfo.ps1” script sample and modify the code so it can be run from shortcut link off the user desktop.

Also, we need to create two additonal script: one to create the shortcut during installation and another to remove the shortcut when uninstalling the application.

This way giving the MSI installer the ability to create and remove the shortcut file.

Lets take look at the sample code prior building the MSI instaler.

Creating Shortcut Script

The following sample script show how to create the shortcut file for the “Get-SystemInfo.exe” script executable during installation process.

For the shortcut, we need to provide the following values:

  1. Target Path – This is the location of the executable.
  2. Arguments – This both the parameters and its values for the executable.
  3. Shortcut Location – This is the location where the shortcut will be created.
  4. *Icon Location – This is the icon location for the shortcut.
  5. WorkingDirectory – This is the location where the executable will start.

*Note: Make sure to provide the Icon information

Below shows the code for creating the **shortcut file:

## - Create a Shortcut in User Desktop: 
$TargetPath = 'C:\Program Files\SAPIEN Technologies, Inc\Get-SystemInfo\Get-SystemInfo.exe';
$Arguments = '-ComputerName ""';
$ShortcutLocation = "$env:USERPROFILE\Desktop\Get-SystemInfo.lnk";
$WScriptShell = New-Object -ComObject WScript.Shell;
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation);
$Shortcut.IconLocation = 'C:\Program Files\SAPIEN Technologies, Inc\Get-SystemInfo\Get-SystemInfo.exe,0';
$Shortcut.TargetPath = $TargetPath;
$Shortcut.WorkingDirectory = 'C:\Program Files\SAPIEN Technologies, Inc\Get-SystemInfo';
$Shortcut.Arguments = $Arguments;

Tip: You can use the Icon stored on the executable file by using the following format:

This script will create the following shortcut file on the user desktop:

Deleting shortcut script

The following code sample script will be use to delete the shortcut file during the uninstall process.

## - Steps to delete existing shortcut link: 
$ShortcutFile = "$env:USERPROFILE\Desktop\Get-SystemInfo.lnk";
Remove-Item $ShortcutFile;

Main Code Sample

We are going to re-use the sample code for creating a command line script to an execute. This was previously use script code in a recent blog post.

Originally, the script executable was meant to run from the console prompt. This time we are making the necessary changes so we can run the executable from a desktop shortcut file.

The following code will be added within the logic that will display the result to the console.

## - Pause after displaying results:
 Read-Host "Press Enter to End Application" 

Then, after saving the changes, we re-package the script, and do a test by executing the application from the file browser.

Now that we got all our scripts ready we can proceed to work on our MSI installer settings.

Steps for building the MSI Installer

You’ll find the Installer setting under the Deploy menu in both PrimalScript, and PowerShell Studio editors.

There are four sections that can be configured:

1. Product Details – Enter the information about the product.

2. Files / Folder – Add additional files needed during the installation: Script(s), images, and/or executable files.

3. Signing – Include a certificate in the installer. (Optional)

4. Custom Actions – Set customized installation steps for different areas of execution stages.

For each of the files added under the “Custom Actions“, there are four area that can be configured:

  1. Properties – Show the properties of the file(s). (Arguments are not needed)
  2. Execution Time – Leave default values.
  3. Execution Options – Leave default values.
  4. Execution Stage – *Depending on your need set script for: “Install“, “Uninstall“, and/or “Maintenance“.

*Note: In this MSI Installer, we are going to use “Execution Stage”: “Install” and “Uninstall”

In the “Custom Actions” is where we added both the create shortcut and delete desktop shortcut scripts.

The script “CreateDesktopShortcut.ps1” will be use during the “Install” execution stage.

The script “DeleteDesktopShortcut.ps1” will be use during the “Uninstall” execution stage.

Now that we got everything configured in the MSI Installer settings, we click on the “Build” option to create the application installer.

This will create the MSI Installer in the folder location previously defined under the settings “Files \ Folders” section.

At this time, the MSI installer is ready to be use.


As you can see, have some room to work with the different setting when creating an MSI installer. And, you need to keep testing your installation solutions to make sure it fits you company need.

Sample Scripts can be downloaded:



As always, if you have any ideas, comments, or feedback, please visit our feedback forum and reference this post.

Max Trinidad is a Technology Evangelist at SAPIEN Technologies Inc., and a Microsoft PowerShell MVP. You can reach him at