PoshCode Logo PowerShell Code Repository

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/520"></script>download | new post

A VI toolkit script to update all VM Guests on the selected hosts

  1. ########################################################
  2. # Created by Brian English
  3. # for Charlotte County Government
  4. # No warranty suggested or implied
  5. ########################################################
  6.  
  7. ########################################################
  8. #connect to VirtualCenter server (i.e. virtual-center-1)
  9.  
  10. if ($args[0] -eq $null)
  11. {$hostName = Read-Host "What host do you want to connect to?"}
  12. else
  13. {$hostName = $args[0]}
  14.  
  15. #connect to selected Virtualcenter or host server
  16. Connect-VIServer $hostName
  17.  
  18. ########################################################
  19. #get all vms listed in virtualcenter
  20. $vms = get-vm
  21.  
  22. ########################################################
  23. #check power state on each vm
  24. #if 'On' update tools
  25.  
  26. Foreach ($i in $vms)
  27. { #if virtualcenter is virtualized skip it
  28.   # a system restart would stop this script
  29.   if ((get-vm -name $i).Name -eq $hostname)
  30.   {"Skipping " + $hostname}
  31.   #if primary DC or DNS is virtualized skip it too
  32.   #elseif ((get-vm -name $i).Name -eq "DNS/DC/DHCP")
  33.   #{"Skipping DNS/DC/DHCP server name"}
  34.   else
  35.   {
  36.     if ((get-vm -name $i).PowerState -eq "PoweredOn")
  37.     { $i
  38.       Get-Date -format "hh:mm:ss"
  39.     update-tools -guest (get-vmguest -vm (get-vm -name $i))
  40.       Get-Date -format "hh:mm:ss"
  41.     }#if
  42.   #}#if
  43. }#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.

Syntax highlighting:


Remember me