PowerShell driving vCenter

Why oh Why did VMWare rebrand PowerShell to be PowerCLI?  I'm pretty sure this is to ties things up with their offering using PHP and the Service Console shell but come on....

Anyways rant off.  This is a great thing.  Being able to use PowerShell to control and query vCenter is genius.  Here is a script-ette I wrote to obtain the amount of guest machines running under a host.  This is useful - I think :) as DRS kinda makes the hosts themselves irrelevant from a capacity planning point of view so you need to look at the clusters, yes I know you can click on the cand you get a list of all the machines and a count too.  However this is a basic HTML page to show how you can avoid paying ££££ for some capacity planning 3rd party tools and just write them yourself!

Anyways here's the code....you'll need PowerCLI installed and need to know how to connect to vCenter...aww shucks I'll show that here too :)

Download and install PowerCLI from VMWare.  You need a valid VMWare account and the target machine must have PowerShell installed (obviously).

http://www.vmware.com/support/developer/PowerCLI/index.html

Once you've done that fire up the PowerCLI and connect to your VCenter

Connect-VIServer -Server <Your vCenter Name>

This shouldn't take long and then you can start all the fun and cool things PowerCLI!

Here's my one liner which gets a count of the Guest VMs per Cluster, I added a column to show the count of the powered on guests as well as the total guests.

Get-Cluster | Select Name, @{N="Total VMs";E={($_ | Get-VM).Count}},@{N="Powered VMs";E={($_ | Get-VM | where {$_.PowerState -eq "PoweredOn"} ).Count}} | Sort Name

Enjoy.

Comments

Popular posts from this blog

PXE booting, MDT and 802.1x

Intune installation requires a wire...or does it?

Powershell VPN connections - PEAP with MSCHAPv2