title: Wix - install and then run a powershell script
body: <p>I know that there are several posts on Wix and PowerShell scripts, but after trying the solutions from those posts, I am still not getting my desired results. To explain my situation, I have created a Wix setup project that will grab 2 Powershell scripts and an msu file from my local machine (running windows 7) and bundle these into an msi file. if I run the msi file on my test virtual machine (running windows server 2008 r2) the files get copied into their specified directory. Great. There is a downside of having a new item show in the Add/Remove programs list, but that would be something I would approach at a later date.</p>
  
  <p>(the Powershell scripts will install the msu, edit a config file and start a service - works fine when running manually)</p>
  
  <p>What I've tried to do after getting the files copied onto the target machine is to run one of the copied Powershell scripts, but so far I've not been able to achieve this. </p>
  
  <p>my .wxs code looks like this (written and compiled using TFS 2010)</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"&gt;
      &lt;Product Id="a89cc681-d617-43ea-817e-1db89b941bf2" Name="Test1" Language="1033" Version="1.0.0.0" Manufacturer="Test1" UpgradeCode="d8db2663-2567-4bb8-9023-09988838eb55"&gt;
      &lt;Package InstallerVersion="200" Compressed="yes" /&gt;
  
  &lt;Media Id="1" Cabinet="media1.cab" EmbedCab="yes" /&gt;
  
  &lt;!-- Set up the directory --&gt;
  &lt;Directory Id="TARGETDIR" Name="SourceDir"&gt;
    &lt;Directory Id="IISTIERINSTALLATION" Name="IISTierInstallation"&gt;
    &lt;/Directory&gt;
  &lt;/Directory&gt;
  
  &lt;!-- Copy the files --&gt;
  &lt;DirectoryRef Id="IISTIERINSTALLATION"&gt;
      &lt;Component Id ="C2WTS_update_file" Guid="11960C39-12EB-4777-B43F-394ADB352DD3"&gt;
        &lt;File Id="C2WTSmsu" Name="Windows6.1-KB974405-x64.msu" Source="C:\PS Scripts\Windows6.1-KB974405-x64.msu" /&gt;
      &lt;/Component&gt;
  
      &lt;Component Id ="C2WTSInstallScript" Guid="C85ED4DB-BDC1-4DD1-84FE-41D7463C6365"&gt;
        &lt;File Id="C2WTSscript1" Name="C2WTS_service_install.ps1" Source="C:\PS Scripts\C2WTS_service_install.ps1" /&gt;
      &lt;/Component&gt;
  
      &lt;Component Id ="C2WTSxmlScript" Guid="AF1F85A7-88F7-4BBA-89D9-6817CFAA74F9"&gt;
        &lt;File Id="C2WTSscript2" Name="Edit_c2wts_config.ps1" Source="C:\PS Scripts\Edit_c2wts_config.ps1" /&gt;
      &lt;/Component&gt;
  &lt;/DirectoryRef&gt;
  
      &lt;Feature Id="ProductFeature" Title="Test1" Level="1"&gt;
          &lt;ComponentRef Id="C2WTS_update_file" /&gt;
    &lt;ComponentRef Id="C2WTSInstallScript" /&gt;
    &lt;ComponentRef Id="C2WTSxmlScript" /&gt;
          &lt;ComponentGroupRef Id="Product.Generated" /&gt;
      &lt;/Feature&gt;
  
  &lt;!-- Run custom action to run the powershell script--&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;SetProperty Id="RunPSscript"
           After="InstallFiles"
           Sequence="execute"
           Value ="&amp;quot;[POWERSHELL.EXE]&amp;quot; -Version 2.0 -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command &amp;quot;&amp;amp; '[#C2WTS_service_install.ps1]' ; exit $$($Error.Count)&amp;quot;" /&gt;
  
  &lt;CustomAction Id="RunPSscript"
                BinaryKey="WixCA"
                DllEntry="CAQuietExec"
                Execute="deferred"
                Return="check"
                Impersonate="yes" /&gt;
  
    &lt;Custom Action="RunPSscript" After="InstallFiles"&gt;
      &lt;![CDATA[NOT Installed]]&gt;
    &lt;/Custom&gt;
  
  &lt;/Product&gt;
  &lt;/Wix&gt;
  </code></pre>
  
  <p>Since adding the custom activity to carry out the powershell script, nothing happens when I run the msi. The files do not appear in their folder like they used to and nothing is installed . Can anyone tell me where I'm going wrong? As said, there are several solutions on the net about similar issues but none have worked for me so far</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I have tried installing the msi with logging turned on, and the log returned the following 2 lines:</p>
  
  <p>CAQuietExec64:  Error 0x80070057: failed to get command line data</p>
  
  <p>CAQuietExec64:  Error 0x80070057: failed to get Command Line</p>
  
  <p>After searching the net for fixes for that error code, I still have not found any answers to help solve the problem. Anyone got any ideas? Any Wix experts out there?</p>
  
  <p>Thanks in advance</p>