2013-01-09 27 views
1

我想使用CMD.exe调用一个提升的powershell脚本来执行任务。当我尝试添加开关时,我可以捕获错误调用powershell.exe给出参数集错误

启动过程:无法使用指定的名称参数解析参数集。 InvalidArgument AmbiguousParameterSet

我知道-RedirectStandardError是有效的,那么这到底是怎么回事呢?

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" 

回答

7

当您运行与参数设置问题,运行此命令来查看哪些参数可在参数组:

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>] 

从这里就可以看出,-Verb和-RedirectStandardOutput不在相同的参数组意味着它们的使用是相互排斥的。

+0

我不知道参数集。谢谢。接受答案。 – Nic

相关问题