Pergunta

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).

Foi útil?

Solução

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

Outras dicas

Try this:

Invoke-Expression -Command "schtasks /query /s $compname /v /fo csv" | ConvertFrom-Csv
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top