6.3. Using Variables as Parameters
So far I have shown you how to provide literal values as the values for parameters. However, you can also use Windows PowerShell variables as the values for parameters.
|
A Windows PowerShell variable is named with a dollar sign followed by uppercase or lowercase alphabetic characters, numeric digits, and/or the underscore character.
|
To use a variable as the value of the parameter, you simply provide the variable name where you would provide a literal value.
In this example, I will show you how to use a variable to supply a parameter value to a cmdlet.
In examples earlier in this chapter, you looked for processes that began with w, using the command
get-process w*
You can achieve the same thing using a variable. First, assign the wildcard w* to the variable $a:
$a = "w*"
Then you can supply the value of the variable to the cmdlet:
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access