Showing posts from February, 2012

Running PowerShell Scripts on Remote Machines from MSBuild

Today's tricky topic is how to get a PowerShell script to execute on a remote machine from a custom MSBuild project file. I won't go into scenarios here, let's get straight to the point. Most of the difficulties encountered in this area revolve around handling parameters, managing paths with spaces, and escaping special characters. Let's say we have a PowerShell script named LogDeploy.ps1 (it's trivial, but I basically want a test case that needs more than one parameter value). This contains a simple function that writes a single-line entry to a log file:   function LogDeployment { param([string]$filepath,[string]$deploydestination) $datetime = Get-Date $filetext = "Deployed package to " + $deploydestination + " on " + $datetime $filetext | Out-File -filepath $filepath -Append } LogDeployment $args[0] $args[1] The LogDeploy.ps1 script accepts two parameters. The first parameter represents the full path to the log file t