PDA

View Full Version : Run Powershell in Basic MSI Project



timstspry
09-23-2010, 10:15 PM
Hello, I need to run a powershell script .ps1 file in a basic MSI project. Anybody have any experience doing this? I have run lots of .cmd files using launchappandwait but I don't think PowerShell is the same animal :)

Thanks!

IlkkaV
12-07-2010, 08:53 AM
I have the same need and would really like to know the recommended way for doing this. I also verified that LaunchAppAndWait doesn't indeed work with PowerShell scripts.

destek
12-07-2010, 10:29 PM
You may be able to get it to run by putting the powershell script in the Behavior and Logic -> Support Files - and launching it from a Custom Action using the powershell.exe. This is only going to work on machines with powershell installed though. The installer will fail on any machine without powershell. This seems risky to me.

IlkkaV
12-08-2010, 01:56 AM
This is only going to work on machines with powershell installed though. The installer will fail on any machine without powershell. This seems risky to me.

I understand the risks, but as the given feature requires SharePoint 2010, having PowerShell present is not a problem as the SharePoint installer makes sure that PowerShell is installed and the platforms it runs on usually have it installed anyway.

IlkkaV
12-08-2010, 08:47 AM
Hmm, this is turning out to be complicated. If the script is located in support files, PowerShell chokes on the curly braces in the SUPPORTDIR path no matter how I try to escape them.

And if I can get the path issue sorted out, then there's the security settings of the target computer. When I ran a PowerShell script from another folder, it told me that the script needs to be signed (doable but awkward) or the script security settings changed (something you shouldn't do from an installer). Sigh.

timstspry
12-08-2010, 11:12 PM
I have not gotten it to work either, but have made some progress on it. I am not sure what you mean by powershell chokes on the curly braces in the path? How are you trying to run powershell? I think if it were me, I would revert back to using LaunchApplication and execute powershell.exe piping in the powershell commands you want as parameters.

One thing that must absolutely be done prior to executing LaunchApplication is executing this command:

Disable(WOW64FSREDIRECTION);

Once control has returned back to IS from PowerShell, you would run this command:

Enable(WOW64FSREDIRECTION);

Hope this helps you out!

Tim

IlkkaV
12-09-2010, 01:39 AM
I have not gotten it to work either, but have made some progress on it. I am not sure what you mean by powershell chokes on the curly braces in the path? How are you trying to run powershell? I think if it were me, I would revert back to using LaunchApplication and execute powershell.exe piping in the powershell commands you want as parameters.

One thing that must absolutely be done prior to executing LaunchApplication is executing this command:

Disable(WOW64FSREDIRECTION);

Once control has returned back to IS from PowerShell, you would run this command:

Enable(WOW64FSREDIRECTION);

Hope this helps you out!

Tim

Thanks for the tip on the WOW64FSREDIRECTION, I'll check it out. What I meant about curly braces is that PowerShell doesn't seem to like any GUIDs in the path, and if the script is stored in support files, it ends up in the SUPPORTDIR, which in turn has the product code in the path. Even when running from the command line, scripts that have a GUID in their path fail to run due to a parse error. So far I haven't found a way to escape those curly braces in a way that would make PowerShell understand them.