switch-parameter

How to pass a switch parameter as a variable / via splatting in PowerShell?

戏子无情 提交于 2021-02-07 07:16:48
问题 If you have multiple parameters which require a value when calling a command or a script, I know you can pass it like this: $parameters = @{ name = "John" last_name = "Doe" } But if the command or script actually just expect -T to indicate something like a flag, but the parameter itself doesn't require a value. How can I set that in a variable? $optionalT = "" if ($itNeedsTheT) $optionalT = "-T" command $optionalT If I do it like that it complains with the following message: Unknown argument

How to pass a switch parameter as a variable / via splatting in PowerShell?

…衆ロ難τιáo~ 提交于 2021-02-07 07:16:29
问题 If you have multiple parameters which require a value when calling a command or a script, I know you can pass it like this: $parameters = @{ name = "John" last_name = "Doe" } But if the command or script actually just expect -T to indicate something like a flag, but the parameter itself doesn't require a value. How can I set that in a variable? $optionalT = "" if ($itNeedsTheT) $optionalT = "-T" command $optionalT If I do it like that it complains with the following message: Unknown argument