Let's assume my script is the following:
param([string]$password)
Write-Host $password
This will return if I launch it this way:
.\myDollarParam.ps1 -Password Pa$sword
Pa
I would like the following output:
Pa$sword
Is there a way to do that aside using ` or \ in the argument ?
Thanks.
The easy way is to enclose it in single quotes. For ex.:
.\myDollarParam.ps1 -Password 'Pa$sword'
Otherwise PowerShell interprets the "$" as the start of a variable, so what you are basically saying in your example, is assign the variable the value "Pa" and then the value stored in the variable "$sword"
A to prove this theory running the following gives me the interesting result:
$sword = "Stuff"
.\myDollarParam.ps1 -Password Pa$sword
PaStuff
By enclosing in single quotes, you are saying pass the literal characters in this string.
The "proper" way to do passwords is to use the ConvertTo-SecureString cmdlt.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With