I am trying to silently execute a PowerShell script from a WiX produced MSI. However, anytime I run the installer PowerShell hangs. Interestingly enough, according to the installer logs the PowerShell script appears to run successfully. Additionally, if I kill the PowerShell process via Task Manager, the installer cancels the installation and rolls back any changes.

I came across a similar situation with a C# project I've been working on. After building the project, I invoke PowerShell in the <AfterBuild> target using MSBuild's <Exec> task, specifying the script to run. If the script did not include the exit keyword, VS2010 "hangs" - which is to say it's actually waiting for PowerShell to complete its task, while PowerShell waits for user input.

If you open up Task Manager or SysInternals Process Explorer, you will see powershell.exe running as if nothing's wrong. If you kill the process, VS2010 (i.e. MSBuild) throws an error.

So you will need to tell PowerShell that you are done with it by adding exit to the script it runs, and all should be well again.

I tried adding exit to the end, unfortunately this had no effect on whether or not the PowerShell process terminates.
–
Ryan TaylorNov 16 '10 at 17:29

:-/ How are you calling PowerShell, and what arguments are you passing to it?
–
Sameer SinghNov 17 '10 at 11:13

Try using the -NoProfile switch in tandem with -File "<pathToScript>", or (less desirable) pass in the script contents as a script block using -Command or -EncodedCommand, ensuring that the keyword 'exit;' is appended to the end. You can even dot-source the script with either of those arguments. You can get information on the list of arguments by typing "powershell.exe /?" either from within PowerShell or the command prompt.
–
Sameer SinghNov 17 '10 at 11:19