调用powershell.exe给出参数设置错误 [英] Calling powershell.exe giving parameter set errors

查看:81
本文介绍了调用powershell.exe给出参数设置错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CMD.exe调用提升的Powershell脚本来执行任务。当我尝试添加开关以便捕获错误时,我得到

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:无法使用指定的名称参数来解析参数集。
InvalidArgument
AmbiguousParameterSet

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

我知道-RedirectStandardError是有效的,所以这是怎么回事?

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"


推荐答案

当遇到参数集问题时,请运行以下命令以查看哪些参数可用参数集:

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

从中您可以看到-Verb和-RedirectStandardOutput是不在同一参数集中,这意味着它们的使用是互斥的。

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

这篇关于调用powershell.exe给出参数设置错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆