After vmware added the update-tools cmdlet, I am trying to figure out some things. Since my old script does not work, I have to discover the wheel again......
1. How do you list VMs which are powered on AND have toolsstatus "Out of date"
2. My new script tells me that one of my variables are empty..
$servers= get-cluster -Name <clustername> | get-vm
foreach ($VM in $servers)
update-tools $VM
Error message is that $VM cannot be <null>
I found one script that I hoped I could fix to suit my needs, but I am not capable of tweaking it to my needs.
$starttime = get-date
#requires -version 2
$OldTools = Get-View -ViewType “VirtualMachine” `
-Property Guest,name `
-filter @{
“Guest.GuestFamily”=”windowsGuest”;
“Guest.ToolsStatus”=”ToolsOld”;
“Guest.GuestState”=”running”
}
Foreach ($VM in $OldTools) {
Get-VM `
| Get-View | Where-Object { ($_.Guest.GuestFamily -eq “windowsGuest”)
-and ( $_.Guest.GuestState -eq “running” ) -and ( $_.Guest.ToolsStatus
-eq “ToolsOld” ) } | Get-VIObjectByVIView | Update-Tools -NoReboot
}
$processed = $oldTools.count – (Get-View -ViewType “VirtualMachine” `
-Property Guest,name `
-filter @{
“Guest.GuestFamily”=”windowsGuest”;
“Guest.ToolsStatus”=”ToolsOld”;
“Guest.GuestState”=”running”
}).count
$ts = New-TimeSpan -Start $starttime
write-host (“{0} out of {1} vm’s were updated in {2}.{3} Min” -f
$processed, $oldTools.count, $ts.Minutes,$ts.Seconds)
I need it to give me the possibility to choose cluster since I have 4 clusters (two that I cannot upgrade and the two others I have to take seperately). I tried adding some cluster specific code, but it just gave me an error saying that "-property" was not recognized (or something)
Anyone out there that could help?