Skip to content

Commit cb29cf3

Browse files
committed
post
1 parent 141114c commit cb29cf3

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

InstallVMSoftware.ps1

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,43 @@
22
# @davidstamen
33
# http://davidstamen.com
44

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
810

9-
$VM = Get-VM $VMName
11+
Foreach ($VMName in $VMs) {
12+
$VM = Get-VM $VMName
1013

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
1619

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
1922

20-
$Command = $DstPath + $File + $Param
21-
$Command2 = "del " + $DstPath + $File
23+
$Command = $DstPath + $File + $Param
24+
$Command2 = "del " + $DstPath + $File
2225

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

Comments
 (0)