PowerCLI

Summary

This is a list of the short PowerCLI scripts I’ve found useful.

Hosts

Comparing Standard Switches between Hosts

Change $host1 and $host2 to appropriate values and this one-liner will show any switches that are on $host1 but not $host2. This will not show what is on $host2 but not $host1.

List of Hardware models (and number in use) across multiple vCenters

Given the array $vctrs, which contains a list of vCenter servers to examine, this script will collate all the hardware models in use and provide a tally of how many you have.

VM

Autoupgrade Tools

Getting a list of VMs that are set to upgrade VMware Tools when the VM is restarted. Conversely, you can edit the line below to show the VMs that aren’t set to upgrade Tools.

List of VMs with attached networks

This will get the list of all VMs and the networks that they are connected to.

Trimming a list of VMs according to name

Simple one this is – if you have VMs which have an identifier in them, for example “dc” for domain controller then to search, it is best to convert the VM name to upper/lower case before doing a comparison.

Snapshots

This will show all the VMs in a vCenter that have a snapshot with their corresponding age.