Powershell and dollar sign in argument


Let’s assume my script is the following:

This will return if I launch it this way:

I would like the following output:

Is there a way to do that aside using ` or \ in the argument ?



The easy way is to enclose it in single quotes. For ex.:

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:

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.


Powershell and dollar sign in argument by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply