PowerShell的新手。我正在尝试使用提升权限运行Start-Process
(通过-Verb RunAs
)并记录结果(通过-RSO output.txt
)。出于某种原因,它不会同时接受。这很好,例如:
Start-Process cmd -Verb RunAs
和此:
Start-Process cmd -RedirectStandardOutput output.txt
但不是这样:
PS C:\> saps cmd -Verb RunAs -RSO output.txt
Start-Process : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ saps cmd -Verb RunAs -RSO output.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Start-Process], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.StartProcessCommand
正在运行Start-Process -?
似乎证实了我的怀疑。请注意-RedirectStandardOutput
和-Verb
在不同部分中的列出方式:
SYNTAX
Start-Process [-FilePath] <string> [[-ArgumentList] <string[]>] [-Credential <pscredential>] [-WorkingDirectory
<string>] [-LoadUserProfile] [-NoNewWindow] [-PassThru] [-RedirectStandardError <string>] [-RedirectStandardInpu
<string>] **[-RedirectStandardOutput <string>]** [-WindowStyle <ProcessWindowStyle> {Normal | Hidden | Minimized |
Maximized}] [-Wait] [-UseNewEnvironment] [<CommonParameters>]
Start-Process [-FilePath] <string> [[-ArgumentList] <string[]>] [-WorkingDirectory <string>] [-PassThru] **[-Verb
<string>]** [-WindowStyle <ProcessWindowStyle> {Normal | Hidden | Minimized | Maximized}] [-Wait]
[<CommonParameters>]
为什么它们是互斥的,我能做些什么来绕过这个?
感谢。