I was recently helping out my friend Paudie O'Riordan with a request from a customer who was looking for a way to collect detailed space utilization for their VMs (VM Home, VMDK & swap) running on VSAN. Today, this level of granularity is not available in the vSphere UI and the customer was interested in both the used and reserved capacity on a per-VM basis. Luckily, this information can be retrieved using the VSAN Management API.

To do so, we just need to use the VsanQueryObjectIdentities() API method, which I have used in the past to retrieve things like "thick" provisioned VM and translating VSAN Object IDs to their friendly VM display name. To retrieve space utilization information, we just need to set the includeSpaceSummary property to be true. While developing the PowerCLI sample script, I found that this specific property is currently not supported when querying vCenter Server and to retrieve this information, you must go directly to each ESXi host within the VSAN Cluster. I have already filed a feature request and it looks like this will be fixed in a future vSphere release.

In the meantime, we still have a solution in which we can use vCenter Server to provide us with a list of ESXi hosts within the VSAN Cluster and given ESXi host credentials, connect to each host using the VSAN API and aggregating the results as if it was done at the VSAN Cluster level. With that, I have created the VSANVMDetailedUsage.ps1 which includes a simple function called Get-VSANVMDetailedUsage which accepts the name of VSAN Cluster as well as an optional VM name for additional filtering. As mentioned earlier, you will need to provide valid credentials to your ESXi hosts (read-only is sufficient) and I have a check in place to ensure the following two variables have been set within the script before it proceeds:

$ESXiHostUsername= ""

$ESXiHostPassword = ""

Here is an example of running the script with just the VSAN Cluster name and no VM filtering, it will retrieve ALL VMs within the VSAN Cluster:

Get-VSANVMDetailedUsage -Cluster "VSAN-Cluster"



Here is an example of running the script with VSAN Cluster name and filtering on a specific VM:

Get-VSANVMDetailedUsage -Cluster "VSAN-Cluster" -VM "Ubuntu-SourceVM"