Listing Orphaned VM folders on vSAN
- Abhilash GB
- May 28
- 2 min read
Recently, I needed to create a list of orphaned virtual machine folders on vSAN datastores across all vCenters. Unfortunately, none of VMware's tools, including Aria Ops, provide a way to generate this list.
So my idea was to generate two separate lists to start with - a list of VMs and a list of VM folders on vSAN datastore and then collate to arrive at an orphaned folder list.
To start with, as vCenter/VROPS didn't have a method to export a list of folders on the datastore, I went online looking for anyone else who had performed a similar task and I stumbled upon a piece of code shared by William Lam(@lamw) nearly a decade ago on GitHub (https://github.com/lamw/vmware-scripts/blob/master/powershell/List-VSANDatastoreFolders.ps1).
Note that the core logic that returns a list of folders for each datastore is in the code shared by William Lam. With all due credit to the code shared by William, my intention in this post is to share the code that can be used to generate a separate set of CSVs for each vCenter in your environment.
Once I had the CSVs generated for datastores in each vCenter, I had to use Microsoft Excel to compare and collate the data needed.
Here is the excel function that I used to mark a VM folder as orphaned or not.
=IF(COUNTIF(A:A,LEFT(B2,13)&"*")>0,"No","Yes")
The function checks if any value in Column-A starts with first 13 characters of B2. If count is > 0, the formula outputs "No"(not orphaned), else "Yes"(orphaned). The character count would depend on the your virtual machine naming convention.

For the function to work correctly, column-A should contain a list of all VM names (I used RVtools for this) and column-B should be a list of all VM folder names (obtained from the output files generated by the code that I've shared in this post).
I hope this saves time for anyone else with a similar requirement.
Commenti