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