Someone had set up a test ESX environment with ~50 ESX hosts on various hardware with various configs. I needed to identify any ESX host in the environment that did not have any persistent storage attached. With this information, I could calculate the size of the NFS mount to request.
I set a variable $Loc that contains the location of the hosts. I also wildcarded the name parameter because there was one host in that location that was not part of my environment. After connecting to my VIServer, this command provided a list of the ESX hosts with no datastores attached.
Get-VMHost -Location $Loc -Name "*test*" | where-object { !@($_ |get-datastore).count} | sort-object name |select-object -property name
Need to know how many hosts are in that list? Put that whole command in parentheses and add .count to the end of it:
(Get-VMHost -Location $Loc -Name "*test*" | where-object { !@($_ |get-datastore).count} | sort-object name |select-object -property name).count
Now, I know I need 8.5GB of storage for each host. Just let PowerCLI do the math:
(Get-VMHost -Location $Loc -Name "*test*" | where-object { !@($_ |get-datastore).count} | sort-object name |select-object -property name).count * 8.5
So there we have it. Technically, the second and third commands up there should also omit the 'sort-object' step, since the order of the objects is unimportant when all we're doing is counting how many there are. But at the command prompt it's easier to use the up arrow and just tack on the ().count