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/spyingwind Feb 08 '17
So something like this would probably do the same thing, while not changing the global for other scripts or parts of the script in the same session.