1

CMD.exe を使用して、昇格した powershell スクリプトを呼び出してタスクを実行しようとしています。エラーをキャプチャできるようにスイッチを追加しようとすると、

Start-Process : 指定された名前パラメーターを使用してパラメーター セットを解決できません。InvalidArgument AmbiguousParameterSet

-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"
4

1 に答える 1

7

パラメーター セットで問題が発生した場合は、次のコマンドを実行して、どのパラメーター セットでどのパラメーターを使用できるかを確認します。

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 が同じパラメーター セットに含まれていないことがわかります。これは、それらの使用が相互に排他的であることを意味します。

于 2013-01-09T23:24:42.197 に答える