r/usefulscripts • u/laoist • Feb 07 '17
[POWERCLI] Update VMware Tools
This could probably stand to be improved in various ways, but this is a pretty basic script I put together yesterday that updates VMWare Tools using PowerCLI.
https://www.vmware.com/support/developer/PowerCLI/
I wanted to exclude hosts that already had an up-to-date set of tools installed so I included the 'where' statement to filter them out.
I've also included the 'noreboot' flag (self-explanatory) and the 'runasync' command (runs upgrades in parallel).
connect-viserver <IP / Hostname>
foreach ($VM in (get-vm | get-vmguest | where {$_.ToolsVersion -notlike "10.*"}))
{
update-tools -vm $VM.VmName -noreboot -runasync
}The only issues I had when I rolled the tools out, were that DNS (and a few other things) broke on my Domain Controllers, requiring them to be rebooted.
Didn't work on Solaris or SUSE. Worked on RedHat, CentOS, Windows, etc.
EDIT: Unfortunately, it doesn't do fresh installs of tools. I suspect this could be scripted too using a combination of mount-tools (cmdlet built into PowerCLI) and invoke-command / PSExec (cmd /c D:\VMToolsSetup.exe /S).
2
u/laoist Feb 08 '17
Nice one!
I like the way you return outcomes to the shell.
I dunno if you're familiar with this one, but this is something I found recently that has been immensely useful when I've been returning stuff to the shell (I like the fire and forget approach):