Powershell variable for cmd argument


I want to use a powershell variable for a cmd argument but I don’t know how to make it.

For example newcredit can be “James” but in my case when I run the command -Credit will only be “$newcredit”.



Single quotes (‘ ‘) do not expand variable values in the string. You can address this by either using double quotes (” “):

Or, by the method I most often use, by using string formatting:

If either of the parameters has a space in it then the parameter will need to be surrounded by double quotes in the output. In that case I would definitely use string formatting:


Powershell variable for cmd argument by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply