I have an MSBuild script that runs PowerShell to do some work on a remote computer, so you need to pass a password to create a remote session, but there is a problem - if the password contains the% character, it is parsed incorrectly -% is missing (ex: pass% word → password, '%' → '' (nothing)).
If I create a variable in PowerShell script $ password = "pass% word", it works fine. I know that% foreach is in PowerShell, so I tried to escape from it with `- but that didn't help. I can also change the password, but this is not an option (at the moment).
So how can I solve this problem?
MSBuild Part
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Test"> <Target Name="Test"> <Exec Command="powershell "& {. 'C:\test.ps1';Test -password '`%25'}"" /> </Target> </Project>
Test.ps1
Function Test { param ( [string]$password = $(throw "Please specify password") ) Write-Host $password }
source share