0

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?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
user3080562
  • 103
  • 1
  • 10

1 Answers1

0

Like the others allready pointed out in the comments, there are two problems here:

  1. You should pass a string-array to -ArgumentList. You do this by seperating you arguments with a ,. Not a whitespace.

  2. To fill in the object $GPUList[1] correct with your " around the string, there are two ways to fill the string with object:

    1. 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])`"

    2. Filling in the variable with a position reference: -ArgumentList 'disable', ('"{0}"' -f $GPUList[1])

Paxz
  • 2,959
  • 1
  • 20
  • 34