1

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

为什么它们是互斥的,我能做些什么来绕过这个?

谢谢。

4

0 回答 0