Mass Upgrade Vmware Tools
Mass Upgrade Vmware Tools – Hey Guys, here’s a cool way you can upgrade VMware Tools across all your VM’s managed by by vCenter, and all this using PowerCli, no more logging in manually to each and every 100’s of VM’s and executing the task manually.
This is an all in one function which can get the job done for you! 🙂
The script assumes that you have a VISession already established to your vcenter server. Or the best way is to code it in your script / function itself by passing the $vcenterserver and $credential as parameters.
Add-pssnapin VMware.VimAutomation.Core Connect-VIServer $vcenterserver -Credential (Get-Credential)
So once we are connected to the vcenter server, lets start building our script, i have broken down the function with detailed explanation.
function Upgrade-ClusterVMTools { [CmdletBinding()] Param ( # Param1 help description Cluster Name [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,Position=0)] $Cluster_Name, # Param2 help description Output File Location [Parameter(Mandatory=$true,Position=1)] $OutputFileLocation ) #  ESXi Host cluster info Write-Host "`nEsx Cluster Name $Cluster_Name.........................." #Create VI Property and use it to displayithe current VMTools version of all VMs New-VIProperty -Name ToolsVersion -ObjectType VirtualMachine -ValueFromExtensionProperty 'Config.tools.ToolsVersion' -Force New-VIProperty -Name ToolsVersionStatus -ObjectType VirtualMachine -ValueFromExtensionProperty 'Guest.ToolsVersionStatus' -Force $VMTools_VM = Get-cluster $Cluster_Name | Get-VM | Select Name, ToolsVersion, ToolsVersionStatus | Sort-Object ToolsVersionStatus Write-Host "`nDisplaying the current VMTools version of all VMs" -ForegroundColor Black -BackgroundColor Green $VMTools_VM | Sort-Object ToolsVersionStatus | ft -AutoSize -Wrap # Creating list of VM's that need upgrade and also have the latest integration tools version $List_VMs_Upgrade = $VMTools_VM | ?{$_.toolsversionstatus -match "guestToolsNeedUpgrade"} $List_VMs_Current = $VMTools_VM | ?{$_.ToolsVersionStatus -match "guestToolsCurrent"} # Saving list of VM's that have current version of vmware tools into a notepad file. $List_VMs_Current | Out-File "$outputfilelocation\VMToolsCurrent.txt" -Force # Updating the User about script progress Write-Host "`nStarting the VMTools upgrade.........................." Start-Sleep -s 2 $Current_time = (Get-Date).DateTime Write-Host "Time now is $Current_time `n" # Array to get count of VM's upgraded $array = @() # Starting the loop foreach($vm in $List_VMs_Upgrade) { # An If Loop to check the VM's accessibility status and out it to a notepad file "Failed VM.txt" if ((Get-VM $VM.name -ErrorAction SilentlyContinue) -eq $null) { write-host "$VM.name is inaccesible" "$VM.name" | Out-File "$outputlocation\Failed_VMs.txt" -Force -Append } else { $VMname = $vm.Name $ToolVer = $vm.Toolsversion Write-Host "`nUpgrading VMTools version on $VMname. Current version is $ToolVer" -ForegroundColor Red -BackgroundColor Black # Upgrading VMTools based on the Guest OS Type Get-VMGuest $VMname | update-Tools -NoReboot $NewToolVer = (get-vm $VMName).Toolsversion Write-Host "`nVMTools upgrade completed on $VMname. New version is $NewToolVer" -ForegroundColor Green -BackgroundColor Black "$($VM.name),$NewToolVer" | Out-File "$outputlocation\Upgraded_VMs.txt" -Force -Append $array+= $VMname } } $Current_time = (Get-Date).DateTime Write-Host "`nVMTools upgrade completed on $($array.count) VMs under Cluster $Cluster_Name" -ForegroundColor Black -BackgroundColor Green Write-Host "`nScript End Time: $Current_time" }
Once you execute the function you should see that all your vm’s tools are upgraded and you get a nice notepad file output with the results.
I hope you enjoyed this blogpost on “Mass Upgrade Vmware Tools” and found this information useful 🙂