我有一个 MSBulild 脚本, 启动 PowerShell 可以在远程计算机上做一些工作, 所以您必须通过密码才能创建远程会话, 但有一个问题 - 如果密码包含% 字符, 那么解析错误 - % 缺失了 (例如: 密码% 字 - & gt; 密码,% - & gt; (没有) ) 。
If I m creating variable in PowerShell script $password = "pass%word" it works fine. I know % is foreach in PowerShell so I tried to escape it using ` - but it didn t helped. Also I can change password, but thats not an option (for now).
那么,我怎样才能解决这个问题呢?
MSBulid 部分
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Test">
<Target Name="Test">
<!-- %25 - it s code for %-->
<Exec Command="powershell "& {. C: est.ps1 ;Test -password `%25 }"" />
</Target>
</Project>
选项卡.ps1
Function Test {
param (
[string]$password = $(throw "Please specify password")
)
Write-Host $password
}