PowerCLI: More One Liners
On my previous post where we counted how many VMs were on each host and the cluster they were in I was asked a couple of questions:
1. How about listing the number of VMs per Resource Pool?
2. How can we extend this to get the templates as well ?
Ok, easy stuff (I thought).
Lets take them in turn…
Question 1. How about listing the number of VMs per Resource Pool?
What you need to remember about this is that even if a VM is not in a resource pool it still has resources available to it which have to come from somewhere so in fact what VMware do behind the scenes is have a hidden resource pool called ‘Resources’ where it places the VM when it is not in any other resource pool.
If you remember this then yes, it is quite easy as below:
Get-ResourcePool | Where {$_.Name -ne “Resources“ }| Select Name, @{N=“NumVM“;E={($_ | Get-VM).Count}} | Sort Name|Export-Csv -NoTypeInformation c:\res-numvm.csv
All we needed to do was to put a Where statement in there to not count the VMs in the ‘pre-made resource pool’
Question 2. How can we extend this to get the templates as well ?
Ahhh, this one is simple I thought, all we need to do is put a count in for Get-Template so the one-liner looks like this:
Get-VMHost |Select @{N=“Cluster“;E={Get-Cluster -VMHost $_}},Name, @{N=“NumVM“;E={($_ |Get-VM).Count}}, @{N=“NumTemplates“;E={($_ |Get-Template).Count}} |Sort Cluster,Name |Export-Csv -NoTypeInformation c:\clu-host-numvm-numtempl.csv
Unfortunately as a Template is basically a special type of VM the cmdlets don’t work like this at the moment, you can not get a list of Templates which exist on a host without delving into the SDK so what I suggest you do is wait until the next version of PowerCLI is released and see if they have fixed this issue. – Current version is PowerCLI V4.0.0.1580
PowerCLI: Folder Name Mismatch PowerCLI: Easy vSwitch & PortGroup Setup











Cool… thanks.
BTW, my order finally arrived today. Love the book!
@Kayser Soze
Thanks, Hal did a great job with his book, you will enjoy reading it.
[...] This post is inspired by a one-liner from Alan Renouf and question from Jason Boche on Twitter. The original one-liner can be found here: http://www.virtu-al.net [...]
Thanks, that willskip the problem but not solve… since I have some RPools that was created with Resources same as hidden….