VMware Cloud Community
kwharrisit
Contributor
Contributor

Update VMTools by groups

I have groups of VM's in various folders that need to have vmtools updated WITHOUT reboots. Is it possible to use the PowerCLI to update vmtools on all all of the machines in a particular folder structure? for example something that would ask which folder you want, then resturn the list of machines in the folders ( and subfolders) and then update without a restart them once you acknowledge the list? This is part of a migration project Im running.

Reply
0 Kudos
1 Reply
RvdNieuwendijk
Leadership
Leadership

Hi Kristopher,

you can use the Get-VMFolderPath function from the thread to get a specific folder. With the Update-Tools cmdlet and the -NoReboot parameter you can update the VMware tools without a reboot. If you combine this information you will get:

function Get-VMFolderPath {
  param([string] $Path)
  
  $Folder = Get-Folder -Name vm
  $FolderNames = $Path.TrimStart("/").TrimEnd("/").Split("/")
  $i = 0
  while ($i -lt $Foldernames.Length -and $Folder) {
    $Folder = Get-Folder -Name $FolderNames[$i++] -Location $Folder -NoRecursion
  }
  $Folder
}

$FolderPath = Read-Host -Prompt "Type the path to the folder containing the VM's for wich you want to update VMware Tools (e.g. /Amsterdam/sales)"
$Folder = Get-VMFolderPath $FolderPath
If ($Folder) {
  $VMs = $Folder | Get-VM
  ""
  "This is the list of VM's in folder $FolderPath"
  $VMs
  ""
  $Answer = Read-Host -Prompt "Are you sure you want to update VMware Tools for all VM's in the list? (Y/[N])"
  if ($Answer -eq "Y") {
    ""
    "Updating VMware Tools"
    $VMs | Where-Object {$_.PowerState -eq "PoweredOn"} | Update-Tools -NoReboot
  }
}
else {
  Write-Error "Folder $FolderPath not found"
}

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos