-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdate-VMware-Tools-All-Win-VMs.ps1
41 lines (35 loc) · 1.48 KB
/
Update-VMware-Tools-All-Win-VMs.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#Author: A.J. Murray
#Created: 9/15/17
#Updated: 12/1/2018
#Get the name of the vCenter Server
$vcenter = Read-Host "Enter the FQDN or IP of your vCenter Server"
#Get credentials for logging into vCenter
$credential = Get-Credential
$Username = $credential.GetNetworkCredential().username
$Password = $credential.GetNetworkCredential().password
#Connect to the vCenter Server - Assuming the script is running under credentials that can connect
Connect-VIServer $vcenter -User $Username -Password $Password
#Get a list of the virtualmachines that are Powered On
$virtualmachines = Get-VM | Where-Object PowerState -eq "PoweredOn" | Select-Object -ExpandProperty Name
#Get Only the Windows VMs
ForEach ($vm in $virtualmachines)
{
#If the VM is a Windows VM...
If (Get-VMGuest $vm | where-object OSFullName -like "Microsoft*")
{
#Update VMware Tools but don't reboot the machine - Reboot may still occur depending on ESXi/vCenter version
Write-Host "Updating VMware tools on $vm"
Update-Tools $vm -NoReboot
}
#If there is no OSFullName detected
elseif(Get-VMGuest $vm | Where-Object OSFullName -Like " *")
{
Write-Host "VMware Tools doesn't appear to be installed on $vm"
}
#If it's not a Windows VM then automatic update is not supported
else {
Write-Host "$vm is not a Windows VM and automatic Update is not supported"
}
}
#Cleanly Disconnect from vCenter
Disconnect-VIServer -Server $vcenter -Confirm:$false