Escape % in parameter passed to Powershell


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



In batch files, the percent sign may be “escaped” by using a double percent sign ( %% ).
So this will do the trick:


Escape % in parameter passed to Powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply