Windows PowerShell:为什么可以';t启动进程是否同时使用-Verb和-RSO?
新手到这里来。我正试图以提升的权限运行Windows PowerShell:为什么可以';t启动进程是否同时使用-Verb和-RSO?,windows,powershell,scripting,wmi,start-process,Windows,Powershell,Scripting,Wmi,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 :
启动进程
(通过-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
运行启动进程-?
似乎验证了我的怀疑。注意-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>]
语法
启动进程[-FilePath][[-ArgumentList][-Credential][-WorkingDirectory
][-LoadUserProfile][-NoNewWindow][-PassThru][-RedirectStandardError][-RedirectStandardInpu
]***[-RedirectStandardOutput]***[-WindowsStyle{Normal | Hidden |最小化|
最大化}][等待][使用新环境][]
启动进程[-FilePath][[-ArgumentList][-WorkingDirectory][-PassThru]**[-Verb
]**[-WindowStyle{Normal | Hidden | Minimized | Maximized}][-Wait]
[]
为什么它们相互排斥,我能做些什么来绕过这一点
谢谢。我现在还不知道发生这种情况的原因。但是我想知道你为什么想要这个?以防我们看到和XYproblem@Matt我在问题的第二句中提到了原因。Windows用于提升进程的底层机制不允许输出重定向。您需要分两步完成:启动提升的进程(可能是Powershell命令行),然后通过输出重定向启动目标进程。我现在还不清楚出现这种情况的原因。但是我想知道你为什么想要这个?以防我们看到和XYproblem@Matt我在问题的第二句中提到了原因。Windows用于提升进程的底层机制不允许输出重定向。您需要分两步完成:启动提升的进程(可能是Powershell命令行),然后通过输出重定向启动目标进程。