私は、コンピュータのリストを取り、いくつかのファイルをリストの各コンピュータに保存する小さなスクリプトを持っています。ユーザーがオプション1を入力すると、program.exeとInstall.ps1ファイルがリモートコンピュータのC:\に保存されます。 program.exeは大体のため1分または2分かかります。ファイルをコピーするときにPowershellがコンピュータのリストをループしないのはなぜですか?
今のところ、2つのファイルは私のリストの最初のコンピュータにのみ保存されます。最初の処理が完了した後、次のコンピュータに移動しません。それがこれをやっている理由はありますか? PowerShellに最初のコンピュータが完了するまで待つ必要がありますか?
CopyFiles関数は問題の関数です。
ここに私のコードです。
cls #clear screen
function CopyFiles {
# Get .exe from source and place at destination workstation
$source2="\\mainserver\program.exe"
$destination2="\\$line\c$\program.exe" # place .exe on C:\ directory of worstation
Copy-Item -Recurse -Filter *.* -path $source2 -destination $destination2 -Force
# Get .bat from source and place at destination workstation
$source3="\\fileserver\Install.ps1"
$destination3="\\$line\c$\Install.ps1" # place .bat on C:\ directory of worstation
Copy-Item -Recurse -Filter *.* -path $source3 -destination $destination3 -Force
}
$a = Get-Content "C:\myscript\computers.txt"
foreach($line in $a)
{
"These options must run in numbered order."
" "
" "
"1. Copy installer to remote computer(s)."
"2. Remove application from remote computer(s)."
"3. Install application from remote computer(s)."
"4. Quit."
" "
"Type number and press Enter."
$UI = Read-Host -Prompt ' '
If ($UI -eq 1) {
CopyFiles
} ELSEIF ($UI -eq 2) {
psexec @C:\myscript\computers.txt -c "\\fileserver\Remove.bat"
} ELSEIF ($UI -eq 3) {
psexec -s @C:\myscript\computers.txt cmd /c "Powershell Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass && PowerShell -noninteractive -file "C:\Install.ps1""
} ELSEIF ($UI -eq 4) {
"Good Bye"
}
}
各コンピュータで同じ操作を行いますか? 「UI」ロジックをループから移動する必要があります。今書いているように、各コンピュータでアクションを実行する前に入力を促します。 –
あなたの権利。ありがとうございました。 –