Friday, November 8, 2013

InstallShield 2013 PowerShell Custom Actions

I was recently trying to execute a PowerShell Custom Action in InstallShield 2013 and for some reason, I could not get it to work!

Therefore, I ended up contacting InstallShield support and discovered the following:

InstallShield uses a 32-bit version of PowerShell by default.

Well, as it turns out, I was attempting to use commands in the Microsoft.Web.Administration namespace that I scripted from IIS Configuration Manager in order to execute my commands.  Of course, I discovered that these commands fail in the 32-bit version of PowerShell and will only work with the 64-bit version of PowerShell!

However, there is a solution.  In order to get 64-bit PowerShell Custom Actions to execute, you will need to set the InstallShield package to run as a 64-bit package by altering the properties in the Template Summary field to x64 instead of Intel (located on the General Information window).



However, there still remains a major limitation with using InstallShield PowerShell Custom Actions in this manner and that is that there is no way to pass arguments to the PowerShell Custom Action!

Therefore, if you are attempting to use PowerShell scripts that require passing arguments to PowerShell, unfortunately, you will not be able to execute them using InstallShield 2013 directly, but the workaround is to simply call the PowerShell executable directly by specifying the path in an EXE and provide the appropriate command line argument in the form of the path to the script file.

Below is a screenshot of the Custom Action configured to run PowerShell:



I have set up the values as Properties to prevent any typing errors from causing the execution of the PowerShell script to fail.

The path to the PowerShell executable that I used was the following (for 64-bit PowerShell): C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

In order to run an external script at the PowerShell command line, you also need to prefix it with the "&" symbol.

Finally, just make sure that your PowerShell Execution Policy is either set to RemoteSigned or Unrestricted first (you can execute this EXE Custom Action before running any others) or else your PowerShell scripts will fail to execute.  (You can do this by setting the IS_PS_EXECUTIONPOLICY in Property Manager to RemoteSigned or Unrestricted). 

Hopefully, in a future version of InstallShield, InstallShield will provide native support for executing PowerShell Custom Actions with argument parameters.




2 comments:

  1. Just as a part of curiosity, I wish to know if there is a way to include powershell custom actions in MST. the method you have highlighted above implements powershell custom actions in ISM. Your help in this regard will really be very helpful

    ReplyDelete