When creating a custom MSI, there are two ways you can run a powershell script right after the installation of an MSI. The first way is by creating your powershell script and placing it under the CustomAction table in MSI. The second method involves creating your text file where you will write out the actual commands that need to be executed.

Two ways of running powershell script from MSI

There are two ways that you can run a powershell script right after the installation of an MSI. Follow the detailed guide to learn how to execute a powershell script after installing an MSI.

  1. Use the custom action table. This method will allow you to add a command line parameter that tells your script where and when to run. You can specify this in the “Command Line” field of your custom action table, as shown below:
  2. Use the Script Installer. The advantage of using this method is that it will automatically detect any dependencies and apply them before running your main script (the one specified in your main section). For example, if another program is installed at the same time as your PowerShell script, then this method will ensure it gets installed first. The disadvantage is that there isn’t much control over what exactly happens during installation since everything gets bundled into one big package. However, this might not be an issue if all files required by both programs are included within their respective installers anyway!

Create your powershell script

To create a powershell script that can be executed from the MSI, you simply need to save a file with the name of your script in the same folder where your MSI is located. This can be done by right-clicking on a blank space inside the folder, clicking New > Text Document and then renaming it with your desired filename.

Next, you must open up your text document and start writing your script. Make sure that it has the correct file extension (.ps1). This can be done by clicking on the file, going to File > Properties and then clicking on “Change” under the “Open with” section. You will then be able to select your desired program for opening the file.

Create CustomAction table in MSI

The second way to run a PowerShell script from an MSI is by creating a custom action table. The steps are the same as those for writing a VBScript, but with some additional constraints:

  • Add a custom action table in your MSI.
  • Add a Run Command Line action to this table and set its command line parameter to the path of your PowerShell script.
  • Set the condition for this action to call on success only if you want it to run every time the installation runs successfully, or change it if you want it only called when certain conditions are met (for example, when an environment variable meets certain criteria).

Install the MSI with script

You can install the MSI with the script. This is easy to do and requires no extra tools or software. You can just run it from the command line, and you will be provided with all the information you need to make it work.

Run the MSI with a custom action. This involves installing an additional program that will allow you to launch your script within the context of your current application’s interface.

Run the MSI with an installer application, which allows for more control over how your scripts are launched than either of these two methods does by itself.

Conclusion

We have looked at two ways to run a powershell script from MSI. We started by discussing how you can use the built-in feature in Windows to run a script right after the installation of an application. In our second example, we created a custom action table in the MSI file that runs our PowerShell script.