The first thing I would change w/ this script is the static root and password entries. You should have the script prompt for this stuff if running interactively or encrypt it in a cred file.
You can use something like this for interactive running:
$Creds = $Host.UI.PromptForCredential("Need Credentials", "Please provide an account with read access to your ESX Server.", "","")
Connect-VIServer esxserver -Credential $Creds
Or something like Hal's script to export credentials in an encrypted file:
http://poshcode.org/501
Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier