title: Running Powershell script in WiX install as an Administrator
body: <p>I have a  WiX installer that needs to run a Powershell script after install. I've gotten to the point where the installer does in fact run the script with this:</p>
  
  <pre><code>&lt;SetProperty Id="RunStartScript"
          Before ="RunStartScript"
          Sequence="execute"
          Value="&amp;quot;C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe&amp;quot; -NonInteractive -ExecutionPolicy Bypass -InputFormat None -NoProfile -File &amp;quot;[INSTALLDIR]Scripts/Start.ps1&amp;quot;" /&gt;
  
  &lt;CustomAction Id="RunStartScript" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="deferred" Return="check" Impersonate="yes" /&gt;
  &lt;InstallExecuteSequence&gt;
        &lt;Custom Action="RunStartScript" Before="InstallFinalize"&gt;NOT Installed OR UPGRADINGPRODUCTCODE&lt;/Custom&gt;
  &lt;/InstallExecuteSequence&gt;
  </code></pre>
  
  <p>However, the msi fails with this error:</p>
  
  <blockquote>
    <p>The script 'Start.ps1' cannot be run because it contains a "#requires" statement for running as Administrator. The current Windows PowerShell session is not running as Administrator. Start Windows PowerShell by using the Run as Administrator option, and then try running the script again.</p>
  </blockquote>
  
  <p>The installer already prompts for an Administrator before install begins, so I assumed the PowerShell command would be running as an admin already, this must not be the case.</p>
  
  <p>I've found some answers that involve adding code to the start of a script to check for Admin privileges and to pass the command and args along to an Admin session, but I was looking for the possibility of another option as this is a signed script that someone else provided so any changes to it would have to go back to them for re-signing.</p>