Does anyone have a script that would update all vm's vmware tools then their h/w verision and then reboot them?
I would like to do this for all our vm's on our cluster not sure if there's an option but if it's possible to randomize the time it's done in between a certain time frame that would be perfect so it would cause too much load at the same time. If not I could just update machines with dev* in their ame then prod* for example.
For Windows the VMware Tools are not guest managed, so that is easier to update.
Do you want to do these VMs in sequence? No parallelism?
If in sequence, you could do something like this (there is a random 'sleep' (between 30 and 60 seconds) after the reboot)
$clusterName = 'MyCluster'
Get-Cluster -Name $clusterName | Get-VM |
ForEach-Object -Process {
if($_.Guest.ExtensionData.ToolsStatus -eq 'toolsOld)'){
Update-Tools -VM $_ -NoReboot
}
if($_.Version -ne 'v11'){
Set-VM -Version v11 -Confirm:$false
}
Restart-VMGuest -VM $_ -Confirm:$false
sleep (Get-Random -Minimum 30 -Maximum 60)
}
And yes, the VCSA has the so-called "guest managed" tools.
You will need a guest OS command (in the VCSA) to update the VMware Tools.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What kind of guest OS do you have on the VMs?
Do you happen to have Linux VM with the builtin open Tools?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Windows, I could install an ubuntu vm if easier?
I forgot to mention we are running ESXI 6.0 hosts with a 6.5 VCSA.
Does the VCSA have the built in tools?
For Windows the VMware Tools are not guest managed, so that is easier to update.
Do you want to do these VMs in sequence? No parallelism?
If in sequence, you could do something like this (there is a random 'sleep' (between 30 and 60 seconds) after the reboot)
$clusterName = 'MyCluster'
Get-Cluster -Name $clusterName | Get-VM |
ForEach-Object -Process {
if($_.Guest.ExtensionData.ToolsStatus -eq 'toolsOld)'){
Update-Tools -VM $_ -NoReboot
}
if($_.Version -ne 'v11'){
Set-VM -Version v11 -Confirm:$false
}
Restart-VMGuest -VM $_ -Confirm:$false
sleep (Get-Random -Minimum 30 -Maximum 60)
}
And yes, the VCSA has the so-called "guest managed" tools.
You will need a guest OS command (in the VCSA) to update the VMware Tools.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
looks good thanks.
Hello Luc
I suppose that I have to list my Windows VM first to make this script first? I need to avoid my Linux machines and also the appliances.
If the VMs are powered on and you have VMware Toos installed, you could use a Where-clause.
Something like this for example
Where-Object {$_.Guest.OSFullName -like "*Windows*"}
To make sure you capture all your VMs with a Windows-based guest OS, you might first pull a report.
Select Name,@{N='OS';E={$_.Guest.OSFullName}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you but the script reveals another problem - - '
It seems that some Linux VM were created with a Windows OS setting...
So I have a few Linux VM in the output!!!
Fortunatelly I can find my Windows VM by their names because the topology was well defined.
Thank you!
What is reported under the Guest property are the values that VMware Tools actually discovered inside the guest OS.
And indeed, you can create a VM for a Linux OS but install a Windows OS on there.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Right, but how can we explain we have some Linux in the output?
I used the remote console of some of the "Windows" listed in the output: those are really Linux...
What does this return?
Select Name,PowerState,
@{N='Tools';E={$_.ExtensionData.Guest.ToolsRunningStatus}},
GuestId,@{N='OS';E={$_.Guest.OSFullName}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I've got my Windows vm of course but also some Linux, like (I don't copy the VM name):
PoweredOn | guestToolsRunning | rhel7_64Guest | Red Hat Enterprise Linux 7 (64-bit) |
Just for you to know, I use "Get-Cluster *"
That is normal with the last snippet of code, it just lists all VMs.
But does the one with Where-clause also list Linux VMs?
Get-Cluster -Name $clusterName | Get-VM |
Where-Object {$_.Guest.OSFullName -like "*Windows*"}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This one works! I have less VM and it doesn't seem to have Linux VMs.
Thanks
I didn't it missed a pipe annd we can make the command line shorter:
get-vm | ? {$_.Guest.OSFullName -match " Windows"}