Domanda

I am trying to run the following command through powershell:

schtasks /query /s $compname /v /fo csv | ConvertFrom-Csv

$compname is set in the first part of the powershell script, but cannot be passed into the command like this. For example, when I try passing in $localhost, I get the following error:

ERROR: Invalid syntax. Value expected for '/s'.
Type "SCHTASKS /QUERY /?" for usage.

Is there a way to pass the variable into this command? I don't plan to change to powershell's native way to access scheduled tasks (through a COM object).

È stato utile?

Soluzione

Working for me, tested in v2. Does it help if you enclose the variable in double quotes (e.g "$compname") ?

$compname = 'localhost'
schtasks /query /s $compname /v /fo csv | ConvertFrom-Csv

Altri suggerimenti

Try this:

Invoke-Expression -Command "schtasks /query /s $compname /v /fo csv" | ConvertFrom-Csv
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top