Outra resposta do tipo "contornar":
cls
$myScriptPurpose = "Welcome!"
$mytrash = "c:\temp\trashFile.txt"
function getCred {
$mycredential = $host.ui.promptforcredential("patch systens", "Please enter your user name and password.", "", "NetBiosUserName")
if(!$mycredential) {
$myErr = "Please enter a value!"
$myErr
exit
}
$mypass = $mycredential.getNetworkCredential().password
$myuser = $mycredential.getNetworkCredential().username
$mydomain = $mycredential.getNetworkCredential().domain
$isDomain1 = [string]::Compare($mydomain, "domain1", $True)
$isDomain2 = [string]::Compare($mydomain, "domain2", $True)
if ($isDomain1 -eq 0) {
$myservers = get-content input\domain1ListOfServers.txt
$myoutputfile = "output-domain1.txt"
}
elseif ($isDomain2 -eq 0) {
$myservers = get-content input\domain2ListOfServers.txt
$myoutputfile = "output-domain2.txt"
}
else {
$myErr = "Unknown domain!"
$myErr
exit
}
$emptyStr | out-file $Myoutputfile
}
function patch {
foreach ($server in $myservers) {
Write-host "Copying folder."
xcopy c:\pathToPatches \$server\c$\temp\patchJob /Y > $myTrash
write-host "Installing patches on $server."
psexec \$server -u $mydomain\$myuser -p $mypass -i c:\temp\patchjob\install.vbs 2> $myTrash
write-host "Cleaning up."
psexec \$server -u $mydomain\$myuser -p $mypass -i del "c:\temp\patchjob\install.vbs" 2> $myTrash
Write-host " Done."
}
}
function cleanUp {
del c:\temp\trashFile.txt
Remove-Variable my*
Remove-Variable is*
}
getCred
patch
cleanup