Reputation: 1399
I havent used powershell a lot, so i am running into an issue with the argument GROUPING_TAGS
. Can anyone please tell me what is wrong here? It works if i remove the grouping_tag argument.
Set-StrictMode -Version 2.0
$ErrorActionPreference = 'Stop'
$file = "C:\Users\xxxx\Desktop\test.exe"
$command = "Start-Process $file @('/install', '/quiet', '/norestart', 'CID=xxxxxxxxxxxx-123', 'GROUPING_TAGS=”Apple,Banana”')"
Invoke-Expression $command
Upvotes: 1
Views: 93
Reputation: 440576
Note:
Invoke-Expression
should generally be avoided and used only as a last resort, due to its inherent security risks. In short: Avoid it, if possible, given that superior alternatives are usually available. If there truly is no alternative, only ever use it on input you either provided yourself or fully trust - see this answer.
Unless you want to execute test.exe
asynchronously, in a new window, also do not use Start-Process
- use direct invocation instead (& $file ....
); see this answer for more information.
In your case, call Start-Process
directly, with a single (positionally implied) -ArgumentList
/ -Args
argument string containing all arguments:
$file = "C:\Users\xxxx\Desktop\test.exe"
Start-Process $file '/install /quiet /norestart CID=xxxxxxxxxxxx-123 GROUPING_TAGS="Apple,Banana"'
Note: It is a bug in Start-Process
that makes passing all arguments as a single string rather than as an array of individual arguments preferable, as explained in this answer.
Upvotes: 2
Reputation: 1399
I figured it out. had to to put a back ticks infront of the "
Set-StrictMode -Version 2.0
$ErrorActionPreference = 'Stop'
$file = "C:\Users\xxxx\Desktop\test.exe"
$command = "Start-Process $file @('/install', '/quiet', '/norestart', 'CID=xxxxxxxxxxxx-123', 'GROUPING_TAGS=`”Apple,Banana`”')"
Invoke-Expression $command
Upvotes: -1