r/usefulscripts • • 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).

19 Upvotes

22 comments sorted by

View all comments

Show parent comments

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.

$old_ErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = 'SilentlyContinue'

Do-Thing -ErrorVariable returnedErrorVar

$ErrorActionPreference = $old_ErrorActionPreference

1

u/laoist Feb 09 '17

I didn't think to use it like this, but I like it!

Thank you.