Hello everyone! Earlier today, I was looking for a way to list the RDM disks that are currently attached and in use by VMs within a specific cluster. See, we’re in the process of decommissioning an old SAN array, and I needed to verify that specific LUNs and RDMs were no longer in use. I came across this post over on the VMware Communities portal, but needed made a minor tweak, as I only wanted to search a specific cluster. By the way… HUGE thanks to user LucD for posting the original script! After running this script, I was then able to search the output to ensure that the LUN WWNs I needed to decommission weren’t in the list.
$report = @() $vms = Get-Cluster -name "Cluster01" | Get-VM | Get-View foreach($vm in $vms){ foreach($dev in $vm.Config.Hardware.Device){ if(($dev.gettype()).Name -eq "VirtualDisk"){ if(($dev.Backing.CompatibilityMode -eq "physicalMode") -or ($dev.Backing.CompatibilityMode -eq "virtualMode")){ $row = "" | select VMName, VMHost, HDDeviceName, HDFileName, HDMode, HDsize, HDDisplayName $row.VMName = $vm.Name $esx = Get-View $vm.Runtime.Host $row.VMHost = ($esx).Name $row.HDDeviceName = $dev.Backing.DeviceName $row.HDFileName = $dev.Backing.FileName $row.HDMode = $dev.Backing.CompatibilityMode $row.HDSize = $dev.CapacityInKB $row.HDDisplayName = ($esx.Config.StorageDevice.ScsiLun | where {$_.Uuid -eq $dev.Backing.LunUuid}).DisplayName $report += $row } } } } $report