Notes of a scripter

PowerCli to get list of unused RDMs on VM Cluster

This page has been updated. Please visit http://notesofascripter.com/?p=23 for the updated script.

Since my last post was about RDMs, lets continue the discusion.  In my work environment we have been consolidating our VMware platform.
So we have been moving VMs with RDMs attached from one cluster to another.  So its been a messy process, and we haven’t had the time to
clean up behind ourselves.  So I have been trying to clean up the RDMs that are attached to the individual clusters.  So the following
script will get all fo the attached RDM LUNs on the cluster.

$Cluster = "VM_Cluster_Name_Here"
$SCSILuns = (Get-Cluster $Cluster | Get-VMHost | Select -First 1 | Get-ScsiLun | Where {$_.LunType -eq "disk"}).CanonicalName

So now we need to get the RDM LUNs that are attached to the VMs that are running on the VM cluster.

(Get-Cluster "VM_Cluster_Name" | Get-VMHost | Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual").ScsiCanonicalName | Sort -Unique

This script will get all RDMs that are attached to the VMs that reside on “VM_Cluster_Name” and list the SCSI canonical names.  This one-liner
has been set to sort the results and only display the unique SCSI canonical names. I do this because the RDMs are attached at the cluster level
so they are presented to all of the VM hosts.

$Cluster = "VM_Cluster_Name_Here"
$AllSCSILUNs = Get-Cluster $Cluster | Get-VMHost | Select -First 1 | Get-ScsiLun | Where {$_.LunType -eq "disk"}
$UsedSCSILUNs = (Get-Cluster "VM_Cluster_Name" | Get-VMHost | Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual").ScsiCanonicalName | Sort -Unique
Compare-Object -ReferenceObject $AllSCSILUNs -DifferenceObject $UsedSCSILUNs | Select InputObject

This final script gets all of the attached RDM LUNs from the cluster level, and then gets the LUNs that are attached to the VMs that are running
on the cluster.  Using the Compare-Object we are able to compare the 2 variables and displays the difference.  This are the LUNs that are unused.
These are the unused RDM that are attached to the cluster.

– Stuart

Exit mobile version