Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Print vSAN objects and components with ESXi Host.
# Print vSAN objects and components with ESXi.
# Created by: gowatana
# Usage:
# PS> Connect-VIServer
# PS> ./list_vsan_components.ps1 <VM Name>
# PS> ./list_vsan_components.ps1 <VM Name> | ft -AutoSize
# PS> ./list_vsan_components.ps1 <VM Name> | Export-Csv -Encoding UTF8 -NoTypeInformation -Path ./vsan_components.csv
$vm_names = $args[0]
function get_vmdk_from_vsan_object {
param (
if($vsan_object.Type -eq "VDisk"){
$vmdk_name = ($vmdks | Where-Object {$_.ExtensionData.Backing.BackingObjectId -eq $vsan_object.VsanUuid}).Name
$vms = Get-VM -Name $vm_names
$vmhost_disks = Get-VMHostDisk | Select-Object `
$vsan_component_map = foreach($vm in $vms){
$vmdks = $vm | Get-HardDisk
$vsan_objects = Get-VsanObject -VM $vm
$vsan_components = Get-VsanComponent -VsanObject $vsan_objects
foreach($vsan_component in $vsan_components){
$vsan_component | Select-Object `
@{N="vSAN_Object_UUID"; E={$_.VsanObject.VsanUuid}},
@{N="Object_Type"; E={$_.VsanObject.Type}},
@{N="VMDK_Name"; E={get_vmdk_from_vsan_object $vmdks $_.VsanObject}},
@{N="Component_Type"; E={$_.Type}},
@{N="ESXi";E={(Get-VMHost -Id ($_.VsanDisk.Id -replace "\/.*")).Name}},
$vsan_component_map | Sort-Object VM, VM_MoRef, Object_Type, vSAN_Object_UUID, Component_Type
Copy link

gowatana commented Sep 19, 2020


  • vCenter 6.7, 7.0
  • PowerCLI 12


PS> Connect-VIServer
PS> ./list_vsan_components.ps1 vm01
PS> ./list_vsan_components.ps1 vm01,vm02 | ft -AutoSize
PS> ./list_vsan_components.ps1 vm0? | Export-Csv -Encoding UTF8 -NoTypeInformation -Path ./vsan_components.csv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment