title: Run PowerShell script from WiX installer
body: <p>I have found a couple of examples showing how to run a PowerShell script from WiX but have not been successful running either of them.  So, I'd like to post what I have with the hope that someone can point out what I am doing wrong.</p>
  
  <pre><code>&lt;!--Install the PowerShell script--&gt;
  &lt;DirectoryRef Id="INSTALLFOLDER"&gt;
    &lt;Component Id="cmp_ShutdownIExplore" Guid="{4AFAACBC-97BB-416f-9946-68E2A795EA20}" KeyPath="yes"&gt;
      &lt;File Id="ShutdownIExplore" Name="ShutdownIExplore.ps1" Source="$(var.ProjectDir)Source\PowerShell\ShutdownIExplore.ps1" Vital="yes" /&gt;
    &lt;/Component&gt;
  &lt;/DirectoryRef&gt;
  
  &lt;!--Define the CustomAction for running the PowerShell script--&gt;
  &lt;CustomAction Id="RunPowerShellScript" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="check" Impersonate="yes" /&gt;
  
  &lt;InstallExecuteSequence&gt;
  
    &lt;!--Invoke PowerShell script --&gt;
    &lt;Custom Action="RunPowerShellScript" After="InstallFiles"&gt;&lt;![CDATA[NOT Installed]]&gt;&lt;/Custom&gt;
  &lt;/InstallExecuteSequence&gt;
  
  &lt;!-- Define custom action to run a PowerShell script--&gt;
  &lt;Fragment&gt;
    &lt;!-- Ensure PowerShell is installed and obtain the PowerShell executable location --&gt;
    &lt;Property Id="POWERSHELLEXE"&gt;
      &lt;RegistrySearch Id="POWERSHELLEXE"
                      Type="raw"
                      Root="HKLM"
                      Key="SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell"
                      Name="Path" /&gt;
    &lt;/Property&gt;
    &lt;Condition Message="This application requires Windows PowerShell."&gt;
      &lt;![CDATA[Installed OR POWERSHELLEXE]]&gt;
    &lt;/Condition&gt;
  
    &lt;!-- Define the PowerShell command invocation --&gt;
    &lt;SetProperty Id="RunPowerShellScript"
             Before ="InstallFiles"
             Sequence="execute"
             Value ="&amp;quot;[POWERSHELLEXE]&amp;quot; -Version 2.0 -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command &amp;quot;&amp;amp; '[#ShutdownIExplore.ps1]' ; exit $$($Error.Count)&amp;quot;" /&gt;
  &lt;/Fragment&gt;
  </code></pre>
  
  <p>When I run the installer I have created I get the following error (from log):</p>
  
  <pre><code>MSI (s) (DC:F8) [11:21:46:424]: Executing op: ActionStart(Name=RunPowerShellScript,,)
  Action 11:21:46: RunPowerShellScript. 
  MSI (s) (DC:F8) [11:21:46:425]: Executing op: CustomActionSchedule(Action=RunPowerShellScript,ActionType=1025,Source=BinaryData,Target=CAQuietExec,)
  MSI (s) (DC:9C) [11:21:46:459]: Invoking remote custom action. DLL: C:\Windows\Installer\MSI8228.tmp, Entrypoint: CAQuietExec
  CAQuietExec:  Error 0x80070057: failed to get command line data
  CAQuietExec:  Error 0x80070057: failed to get Command Line
  CustomAction RunPowerShellScript returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
  Action ended 11:21:46: InstallFinalize. Return value 3.
  </code></pre>
  
  <p>I am not at all clear what this error is trying to say.  Are my internal references bad?  Is the command to execute the script bad?  Something else?</p>
  
  <p>Any help is most appreciated and thanks in advance.</p>