How to pass a switch parameter as a variable / via splatting in PowerShell?
问题 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