Dominic Brunetti
Dominic Brunetti

Reputation: 1069

How do I set a variable if a command line parameter is "present" in powershell?

If I define the command line parameters as such:

[CmdletBinding()]
Param(
[Parameter(Mandatory=$False)]
[string[]$myString
)

How do I evaluate if $myString is present and create a variable to represent yes or no?

Many thanks.

Upvotes: 0

Views: 304

Answers (1)

steven
steven

Reputation: 518

You could simply do a null check on the variable:

if ($myString) {
 'set true variable' 
} else { 
 'set false variable' 
}

Upvotes: 2

Related Questions