13

編集::::現在の問題の状態については、一番下を参照してください。

現在の設定では、バッチファイルは次のようにPowerShellスクリプトを呼び出します

powershell D:\path\powershellScript.v32.ps1 arg1 arg2 arg3 arg4

これを別のPowerShellを呼び出すPowerShellスクリプトに変換したいと思います。ただし、開始プロセスの使用に問題があります。これは私が現在持っているものですが、実行すると次のようになります

No application is associated with the specified file for this operation

これは実行中のPowerShellです

$powershellDeployment = "D:\path\powershellScript.v32.ps1"
$powershellArguments = "arg1 arg2 arg3 arg4"
Start-Process $powershellDeployment -ArgumentList $powershellArguements -verb runas -Wait

編集::::::

以下の助けにより、私は今、次のものを持っています

$username = "DOMAIN\username"
$passwordPlainText = "password"     
$password = ConvertTo-SecureString "$passwordPlainText" -asplaintext -force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username,$password

$powershellArguments = "D:\path\deploy.code.ps1", "arg1", "arg2", "arg3", "arg4"
Start-Process "powershell.exe" -credential $cred  -ArgumentList $powershellArguments

ただし、リモートマシンからこのスクリプトを実行すると、使用されているユーザー名にマシンへの完全な管理者アクセス権がある場合でも、「アクセス拒否」エラーが発生します。

4

2 に答える 2

21

を使用し、引数リストStart-Process powershell.exeの引数としてスクリプトへのパスを渡す必要があります。-FileこのNo application...ビットは、マシン上の.ps1ファイルで動作するように設定されたデフォルトのアプリケーションがないことを意味します。Right Click -> Open With -> Select Application -> check "Use this program as default...".ps1ファイルで一口全体を実行すると、メッセージは消えます。私のデフォルトのプログラムはメモ帳なのでStart-Process、.ps1で使用すると、その中にポップアップ表示されます。

編集:

すべてをまとめるには...

Start-Process powershell.exe -ArgumentList "-file C:\MyScript.ps1", "Arg1", "Arg2"

$powershellArgumentsまたは、キースが言うように定義する場合( $powershellArguments = "-file C:\MyScript.ps1", "arg1", "arg2", "arg3", "arg4")、次のようになります。

Start-Process powershell.exe -ArgumentList $powershellArguments
于 2012-08-20T16:34:00.880 に答える
7

これを変える:

$powershellArguments = "arg1 arg2 arg3 arg4"

$powershellArguments = "arg1", "arg2", "arg3", "arg4"

この-ArgumentListパラメーターは、引数の配列を想定しています。すべての引数を含む単一の文字列ではありません。

于 2012-08-20T16:20:07.083 に答える