title: How do I run a PowerShell script inside of MSBuild?
body: <p>Maybe there's something wrong with my installation, I'm not quite sure.
  I've spent about two days looking and trying different solutions.  It's obvious that people have done it, but their examples aren't working for me yet.</p>
  
  <p>I am going to eventually want to run an external PowerShell script, but I will be happy to get this working first:</p>
  
  <p><strong>psTest.build:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Test"&gt;
  
    &lt;Target Name="Test"&gt;
      &lt;Exec Command='powershell -Command "Write-Host &amp;quot;Hello, world!&amp;quot;"' /&gt;
    &lt;/Target&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>Running the build script:</p>
  
  <pre><code>PS D:\&gt; msbuild .\psTest.build /Target:test
  Microsoft (R) Build Engine version 12.0.30723.0
  [Microsoft .NET Framework, version 4.0.30319.18444]
  Copyright (C) Microsoft Corporation. All rights reserved.
  
  Build started 10/16/2014 3:20:31 PM.
  Project "D:\psTest.build" on node 1 (test target(s)).
  Test:
    powershell -Command "Write-Host "Hello, world!""
    I n t e r n a l   W i n d o w s   P o w e r S h e l l   e r r o r .     L o a d i n g   m a n a g e d   W i n d o w s
       P o w e r S h e l l   f a i l e d   w i t h   e r r o r   8 0 0 7 0 0 0 2 .
  
  
  D:\psTest.build(5,5): error MSB3073: The command "powershell -Command "Write-Host "Hello, world!"" exited with c
  ode -65536.
  Done Building Project "D:\psTest.build" (test target(s)) -- FAILED.
  
  
  Build FAILED.
  
  "D:\psTest.build" (test target) (1) -&gt;
  (Test target) -&gt;
    D:\psTest.build(5,5): error MSB3073: The command "powershell -Command "Write-Host "Hello, world!"" exited with
   code -65536.
  
      0 Warning(s)
      1 Error(s)
  
  Time Elapsed 00:00:01.10
  </code></pre>
  
  <p>I've also tried using using MSBuild Extension Pack, but I still end up getting the same error.
  So, it feels like there is a major disconnect, which once that's out of the way, everything else should just fit.</p>