Llamar a powershell.exe dando errores de conjunto de parámetros

I am trying to use CMD.exe to call an elevated powershell script to perform a task. When I attempt to add switches so that I can capture errors I get

Start-Process : Parameter set cannot be resolved using the specified name parameters. InvalidArgument AmbiguousParameterSet

I know that -RedirectStandardError is valid, so what is going on here?

set Command1='C:\users\administrator\desktop\DoStuff.ps1'
set Output='C:\Users\nadministrator\desktop\output.txt'
powershell.exe -NoProfile "start-process powershell.exe -wait -RedirectStandardError %Output% -argumentlist %Command1% -verb RunAs"

preguntado el 09 de enero de 13 a las 22:01

1 Respuestas

When you run into problems with parameter sets run this command to see which parameters are available in which parameter sets:

C:\PS> Get-Command Start-Process -Syntax

Start-Process [-FilePath] <string> [[-ArgumentList] <string[]>] [-Credential
<pscredential>] [-WorkingDirectory <string>] [-LoadUserProfile] [-NoNewWindow]
[-PassThru] [-RedirectStandardError <string>] [-RedirectStandardInput <string>]
[-RedirectStandardOutput <string>] [-Wait] [-WindowStyle <ProcessWindowStyle>]
[-UseNewEnvironment] [<CommonParameters>]

Start-Process [-FilePath] <string> [[-ArgumentList] <string[]>]
[-WorkingDirectory <string>] [-PassThru] [-Verb <string>] [-Wait] [-WindowStyle
<ProcessWindowStyle>] [<CommonParameters>]

From this you can see that -Verb and -RedirectStandardOutput are not in the same parameter set meaning their use is mutually exclusive.

Respondido el 09 de enero de 13 a las 23:01

I was not aware of the parameter sets. Thanks. Answer accepted. - Nic

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.