gpt4 book ai didi

powershell - 调用powershell.exe给出参数设置错误

转载 作者:行者123 更新时间:2023-12-03 00:26:51 28 4
gpt4 key购买 nike

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

Start-Process:无法使用指定的名称参数来解析参数集。
无效的论点
模糊参数集

我知道-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"

最佳答案

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

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不在同一参数集中,这意味着它们的使用是互斥的。

关于powershell - 调用powershell.exe给出参数设置错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14247854/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com