简体   繁体   中英

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.

You could simply do a null check on the variable:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM