cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
timstspry
Level 7

Run Powershell in Basic MSI Project

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!
Labels (1)
0 Kudos
(6) Replies
IlkkaV
Level 7

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.
0 Kudos
Videstra
Level 7

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.
0 Kudos
IlkkaV
Level 7

destek wrote:
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.
0 Kudos
IlkkaV
Level 7

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.
0 Kudos
timstspry
Level 7

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
0 Kudos
IlkkaV
Level 7

timstspry wrote:
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.
0 Kudos