Question:
I have a MSBuild script that starts PowerShell to perform some work on remote computer so you have to pass password to create remote session, but there is issue – if password contains % character it is parsed wrong – % is missing (ex: pass%word -> password, ‘%’ -> ”(nothing)).
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).
So how can I solve this issue?
MSBuild part
1 2 3 4 5 6 7 |
test.ps1
1 2 3 4 5 6 7 8 |
Function Test { param ( [string]$password = $(throw "Please specify password") ) Write-Host $password } |
Answer:
In batch files, the percent sign may be “escaped” by using a double percent sign ( %% ).
So this will do the trick:
1 2 |