|
2 | 2 | # @davidstamen
|
3 | 3 | # http://davidstamen.com
|
4 | 4 |
|
5 |
| -param( |
6 |
| - [string]$VMName |
7 |
| -) |
| 5 | +#Define Variables |
| 6 | +Write-Host "Prompt For Guest Credentials" -ForegroundColor Yellow |
| 7 | +$Cred = Get-Credential |
| 8 | +$VMs = "VM1","VM2" |
| 9 | +#$VMs = Get-VM VM* | Sort Name |
8 | 10 |
|
9 |
| -$VM = Get-VM $VMName |
| 11 | +Foreach ($VMName in $VMs) { |
| 12 | + $VM = Get-VM $VMName |
10 | 13 |
|
11 |
| -$File = "VMware-v4vdesktopagent-x86_64-6.2.0-3295266.exe" |
12 |
| -$Param = "/s /v/qn REBOOT=Reallysuppress" |
13 |
| -$SrcPath = "c:\" |
14 |
| -$DstPath = "c:\temp\" |
15 |
| -$Fullpath = $SrcPath + $File |
| 14 | + $File = "VMware-v4vdesktopagent-x86_64-6.2.0-3295266.exe" |
| 15 | + $Param = "/s /v/qn REBOOT=Reallysuppress" |
| 16 | + $SrcPath = "c:\" |
| 17 | + $DstPath = "c:\temp\" |
| 18 | + $Fullpath = $SrcPath + $File |
16 | 19 |
|
17 |
| -Write-Host Copying $Fullpath to $VMName |
18 |
| -Copy-VMGuestFile -VM $VM -Source $Fullpath -Destination $DstPath -LocalToGuest -Force |
| 20 | + Write-Host Copying $Fullpath to $VMName -ForegroundColor Cyan |
| 21 | + Copy-VMGuestFile -VM $VM -Source $Fullpath -Destination $DstPath -LocalToGuest -GuestCredential $Cred -Force |
19 | 22 |
|
20 |
| -$Command = $DstPath + $File + $Param |
21 |
| -$Command2 = "del " + $DstPath + $File |
| 23 | + $Command = $DstPath + $File + $Param |
| 24 | + $Command2 = "del " + $DstPath + $File |
22 | 25 |
|
23 |
| -Write-Host Executing $Command within guest operating system of $VMName |
24 |
| -$Result = Invoke-VMScript -VM $VM -ScriptText $Command |
25 |
| -$ExitCode = $Result.ExitCode |
26 |
| -Write-Host $VMName returned exit code $ExitCode |
27 |
| - |
28 |
| -Write-Host Executing $Command2 within guest operating system of $VMName |
29 |
| -$Result2 = Invoke-VMScript -VM $VM -ScriptText $Command2 |
30 |
| -$ExitCode2 = $Result2.ExitCode |
31 |
| -Write-Host $VMName returned exit code $ExitCode2 |
| 26 | + Write-Host Executing $Command within guest operating system of $VMName -ForegroundColor White |
| 27 | + $Result = Invoke-VMScript -VM $VM -ScriptText $Command -GuestCredential $Cred |
| 28 | + $ExitCode = $Result.ExitCode |
| 29 | + if ($ExitCode = "0") { |
| 30 | + Write-Host $VMName returned exit code $ExitCode -ForegroundColor Green |
| 31 | + } |
| 32 | + Else { |
| 33 | + Write-Host $VMName returned exit code $ExitCode -ForegroundColor Red |
| 34 | + } |
| 35 | + Write-Host Executing $Command2 within guest operating system of $VMName -ForegroundColor White |
| 36 | + $Result2 = Invoke-VMScript -VM $VM -ScriptText $Command2 -GuestCredential $Cred |
| 37 | + $ExitCode2 = $Result2.ExitCode |
| 38 | + if ($ExitCode2 = "0") { |
| 39 | + Write-Host $VMName returned exit code $ExitCode2 -ForegroundColor Green |
| 40 | + } |
| 41 | + Else { |
| 42 | + Write-Host $VMName returned exit code $ExitCode2 -ForegroundColor Red |
| 43 | + } |
| 44 | +} |
0 commit comments