Skip to content

Instantly share code, notes, and snippets.

Embed
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 (
$vmdks,
$vsan_object
)
if($vsan_object.Type -eq "VDisk"){
$vmdk_name = ($vmdks | Where-Object {$_.ExtensionData.Backing.BackingObjectId -eq $vsan_object.VsanUuid}).Name
$vmdk_name
}else{
$vsan_object.Type
}
}
$vms = Get-VM -Name $vm_names
$vmhost_disks = Get-VMHostDisk | Select-Object `
@{N="VMHost";E={$_.VMHost.Name}},
@{N="CanonicalName";E={$_.ScsiLun.CanonicalName}}
$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="VM";E={$vm.Name}},
@{N="VM_MoRef";E={$vm.ExtensionData.MoRef.Value}},
@{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}},
@{N="CanonicalName";E={$_.VsanDisk.CanonicalName}}
}
}
$vsan_component_map | Sort-Object VM, VM_MoRef, Object_Type, vSAN_Object_UUID, Component_Type
@gowatana
Copy link
Author

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