私はマシンを遠隔から更新するためのスクリプトを書いており、現在はスクリプト自体のユーザー名、パスワード、パスを引数として渡していますが、引き続きリモートマシンに接続するためのユーザー名とパスワードを要求します。どこが間違っていますか? &」:-prompt「を押して終了します...」スクリプトで渡された引数をPowerShellで使用して正常に実行させるにはどうすればよいですか?
[string][ValidateNotNullOrEmpty()]$credentials=$args[0]
[string][ValidateNotNullOrEmpty()]$password=$args[1]
$destination =$args[2]
$destinationHome =$args[3]
$sourcePathBat = $args[4]
$sourcePathZip = $args[5]
$command = "cmd.exe /c \\192.168.50.23\deployment\deploy-smartcheck-kiosk.bat upgrade"
$secPassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$Params = New-Object System.management.automation.PSCredential($credentials, $secPassword)
Write-Host $args[0]
Write-Host $args[1]
Write-Host $args[2]
Write-Host $args[3]
Write-Host $args[4]
Write-Host $args[5]
net use $destination $secPassword /USER:$credentials
Copy-Item -Path $sourcePathBat -Destination $destinationHome;
Copy-Item -Path $sourcePathZip -Destination $destinationHome;
Write-Host "Performing remote command..."
Write-Host $command
Invoke-Command -ComputerName 192.168.50.23 -Credential $Params -ErrorAction Stop -ScriptBlock {
param($command)
Write-Host "Trying to execute remote command ($command)"
Invoke-Expression -Command: "$command"
} -ArgumentList $command
読み取りホストの変更
のカップルと
更新されたスクリプトは、これは私が現在のスクリプトを実行している方法です。 \ execute-copy-and-command - Copy.ps1 'test2 test3 test4
何か助けていただければ幸いです。
はあなたが '入力-PSSession'後にその部分を期待しているチェックを持つことができ、他のコンピュータ上で実行? – PetSerAl
@PetSerAl自分のマシンから同じドメイン上の別のマシンにファイルをリモート転送しています。他のマシンで実行される唯一のものは、Invoke-Command以降です。 – bluebrigade23