parameter-splatting

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

Use a variable in PowerShell to pass multiple arguments to an external program

喜欢而已 提交于 2019-12-23 04:05:24
问题 I downloaded the npm package for merge junit reports - https://www.npmjs.com/package/junit-merge. The problem is that I have multiple files to merge and I am trying to use string variable to hold file names to merge. When I write the script myslef like: junit-merge a.xml b.xml c.xml This works, the merged file is being created, but when I do it like $command = "a.xml b.xml c.xml" junit-merge $command This does not work. The error is Error: File not found Has anyone faced similar issues? 回答1: