Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install Powershell script with WiX

I have a signed PowerShell script which I want to deploy to a target machine via a WiX installer. Is it possible to give the script the execution rights?

Regards, forki

  • EDIT - It seems I have to call Powershell with --Command Set-ExecutionPolicy RemoteSigned, but I can't get it working. I see the Powershell command window opening but it doesn't change the policy.
<Property Id="POWERSHELLEXE"><![CDATA[C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe]]></Property>

<CustomAction Id="AllowPS"
  Property="POWERSHELLEXE"
  ExeCommand="-NoLogo -NoProfile -Command Set-ExecutionPolicy RemoteSigned"
  Execute="deferred"
  Return="check"/>

<InstallExecuteSequence>
   ..
  <Custom Action="AllowPS" Before="InstallFinalize"/>
   ...
</InstallExecuteSequence>
like image 758
forki23 Avatar asked Jun 07 '26 18:06

forki23


2 Answers

Group Policy is the better way to go about it,

I think the reason that your call to PowerShell.exe is not changing the execution policy is because the cmdlet is set to prompt the user before changing the execution policy. The -Force parameter will force the change without an additional prompt.

like image 70
Steven Murawski Avatar answered Jun 10 '26 19:06

Steven Murawski


If you are using PowerShell 2.0, there is a -ExecutionPolicy parameter on PowerShell.exe. Try something like this in one single custom action to run the script.

ExeCommand="-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -File <scrptpath>"
like image 27
Keith Hill Avatar answered Jun 10 '26 17:06

Keith Hill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!