I'm trying to pass a variable to this command in PowerShell
Start-Process $devconloc -ArgumentList "\disable" '"'$GPUList[1]'"' -ErrorAction Stop
$GPUList[0] is a hardware ID and needs to be passed to devcon.exe in quotes:
"PCI\VEN_10DE&DEV_1CBB&SUBSYS_087D1028&REV_A1\4&44A1B07&0&0008"
But I get the following error
Start-Process : A positional parameter cannot be found that accepts argument '"'.
Any ideas what is happening?
Like the others allready pointed out in the comments, there are two problems here:
You should pass a string-array to
-ArgumentList. You do this by seperating you arguments with a,. Not a whitespace.To fill in the object
$GPUList[1]correct with your"around the string, there are two ways to fill the string with object:Escaping the
"in the string with`and phrasing the variables in()to make sure the array position will be taken in notice :-ArgumentList '\disable', `"$($GPUList[1])`"Filling in the variable with a position reference:
-ArgumentList 'disable', ('"{0}"' -f $GPUList[1])