PoshCode Logo PowerShell Code Repository

Update VM Tools by Brian English 3 years ago
View followups from Brian English | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/518"></script>download | new post

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

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