Friday, July 19, 2013

Changing ESXi IP address and default route via command line

esxcfg-vmknic "Management Network" -i [newip] -n [newsubnetmask]
esxcfg-route -d default 0.0.0.0 [olddefaultgw]
esxcfg-route -a default 0.0.0.0 [newdefaultgw]
/sbin/services.sh restart

Friday, March 29, 2013

PowerCLI - Removing inaccessible VM's from inventory

In my lab I often destroy and re-create Nutanix clusters which sometimes leaves stale, inaccessible datastores as well as a bunch of inaccessible VM's. The following script will remove all these inaccessible VM's from inventory (Thanks to my colleague Steven for this one):
Get-Cluster -Name $clustername | Get-VM | Get-View | Where {-not $_.Config.Template} | Where{$_.Runtime.ConnectionState -eq “invalid” -or $_.Runtime.ConnectionState -eq “inaccessible”} | %{Remove-VM -VM $_.Name}