Update VM Tools (modification of post by Brian English view diff)
View followups from Brian English | diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/519"></script>download | new post
A VI toolkit script to update all VM Guests on the selected hosts
- ########################################################
- # Created by Brian English
- # for Charlotte County Government
- # No warranty suggested or implied
- ########################################################
- ########################################################
- #connect to VirtualCenter server (i.e. virtual-center-1)
- if ($args[0] -eq $null)
- {$hostName = Read-Host "What host do you want to connect to?"}
- else
- {$hostName = $args[0]}
- #connect to selected Virtualcenter or host server
- Connect-VIServer $hostName
- ########################################################
- #get all vms listed in virtualcenter
- $vms = get-vm
- ########################################################
- #check power state on each vm
- #if 'On' update tools
- Foreach ($i in $vms)
- { #if virtualcenter is virtualized skip it
- # a system restart would stop this script
- if ((get-vm -name $i).Name -eq $hostname)
- {"Skipping " + $hostname}
- #if primary DC or DNS is virtualized skip it too
- #elseif ((get-vm -name $i).Name -eq "DNS/DC/DHCP")
- #{"Skipping DNS/DC/DHCP server name"}
- else
- {
- if ((get-vm -name $i).PowerState -eq "PoweredOn")
- { $i
- Get-Date -format "hh:mm:ss"
- update-tools -guest (get-vmguest -vm (get-vm -name $i))
- Get-Date -format "hh:mm:ss"
- }#if
- #}#if
- }#foreach
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository