title: Executing msbuild task from powershell
body: <p>I am following this blog: <a href="http://sedodream.com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx" rel="nofollow noreferrer">http://sedodream.com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx</a> </p>
  
  <p>it's linked in this question as answer: <a href="https://stackoverflow.com/questions/8989737/web-config-transforms-outside-of-microsoft-msbuild">Web.Config transforms outside of Microsoft MSBuild?</a></p>
  
  <p>Every step works as described but I want to call the transformation from a powershell script.
  I want to do this command in powershell <code>msbuild trans.proj /t:Demo</code>
  I found some forums saying that I should use <code>invoke-expression</code></p>
  
  <p>When I try I get this error</p>
  
  <p>Powershell:</p>
  
  <pre><code>Invoke-Expression $msbuild transformCommand.proj /t:Demo
  </code></pre>
  
  <p>Result</p>
  
  <pre><code>Invoke-Expression : Cannot bind argument to parameter 'Command' because it is null.
  At D:/Somewhere
  + Invoke-Expression &lt;&lt;&lt;&lt;  $msbuild transformCommand.proj /t:Demo
      + CategoryInfo          : InvalidData: (:) [Invoke-Expression], ParameterBindingValidationException
      + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.InvokeExpre
     ssionCommand
  </code></pre>
  
  <p>I also tried:</p>
  
  <pre><code>Invoke-Expression msbuild transformCommand.proj /t:Demo
  </code></pre>
  
  <p>With result</p>
  
  <pre><code> D:\Somewhere
  Invoke-Expression : A positional parameter cannot be found that accepts argument 'transformCommand.proj'.
  At D:\Redgate\Communited.Timeblockr.Api\PreDeploy1.ps1:14 char:18
  + Invoke-Expression &lt;&lt;&lt;&lt;  msbuild transformCommand.proj /t:Demo
      + CategoryInfo          : InvalidArgument: (:) [Invoke-Expression], ParameterBindingException
      + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeExpressionCommand
  </code></pre>
  
  <p>Small note: this is my first time using powershell.</p>
  
  <p>TransformCommand.proj </p>
  
  <pre><code>&lt;Project ToolsVersion="4.0" DefaultTargets="Demo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
      &lt;UsingTask TaskName="TransformXml"
               AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/&gt;
      &lt;Target Name="Demo"&gt;
          &lt;TransformXml Source="Web.Test.config"
                        Transform="transform.xml"
                        Destination="Web.acceptatie.config"/&gt;
      &lt;/Target&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>My questions are:
  Is this possible? And how is it possible?</p>
  
  <p>Edit:</p>
  
  <pre><code>$a = "Path\transformCommand.proj /t:Demo"
  #Invoke-Expression $msbuild $a
  
  Start-Process -FilePath "C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe" -ArgumentList $a | Write-Host 
  </code></pre>
  
  <p>This actually does everything I need.. </p>
  
  <p>Still if there are ways to do this more "indepent" or better ways, please post it.</p>