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>]
なぜそれらは相互に排他的であり、これを回避するにはどうすればよいですか?
ありがとう。