VMware Cloud Community
internetrush1
Contributor
Contributor

Find list of RDM luns not attached to VM's in PowerCLI

I need a list of RDM disks that are attached to a specific host. I've found others looking for VM's with attached RDM and they can reference :

foreach($dev in $vm.Config.Hardware.Device) {
if(($dev.gettype()).Name -eq "VirtualDisk") {  
          if($dev.Backing.CompatibilityMode -eq "physicalMode"

But this is not what i need, in fact, it is the inverse of what i need.

$VMhost = get-cluster | foreach { $_ | get-vmhost | Where-object {$_.name -match $HOSTNAME}}

My best guess is something to do with:

$VMhost |  get-vmhostdisk -vmhost $vmhost.name

Which yields all the attached devices:

Cylinders        Property   System.Int64 Cylinders {get;}                                               
DeviceName       Property   System.String DeviceName {get;}                                             
ExtensionData    Property   System.Object ExtensionData {get;}                                          
Heads            Property   System.Int32 Heads {get;}                                                   
Id               Property   System.String Id {get;}                                                     
ScsiLun          Property   VMware.VimAutomation.ViCore.Types.V1.Host.Storage.Scsi.ScsiLun ScsiLun {get;}
Sectors          Property   System.Int32 Sectors {get;}                                                 
TotalSectors     Property   System.Int64 TotalSectors {get;}                                            
Uid              Property   System.String Uid {get;}                                                    
VMHost           Property   VMware.VimAutomation.ViCore.Types.V1.Inventory.VMHost VMHost {get;}


2nd guess is something to do with :

$LunList = get-scsilun -vmhost $vmhost.name

BlocksToSwitchPath   Property   System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] BlocksToSwitchPath {get;} 
CanonicalName        Property   System.String CanonicalName {get;}                                                                                                       
CapacityMB           Property   System.Nullable`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] CapacityMB {get;}         
CommandsToSwitchPath Property   System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] CommandsToSwitchPath {get;}
ConsoleDeviceName    Property   System.String ConsoleDeviceName {get;}                                                                                                   
ExtensionData        Property   System.Object ExtensionData {get;}                                                                                                       
HostId               Property   System.String HostId {get;}                                                                                                              
Id                   Property   System.String Id {get;}                                                                                                                  
IsLocal              Property   System.Boolean IsLocal {get;}                                                                                                            
Key                  Property   System.String Key {get;}                                                                                                                 
LunType              Property   System.String LunType {get;}                                                                                                             
Model                Property   System.String Model {get;}                                                                                                               
MultipathPolicy      Property   VMware.VimAutomation.ViCore.Types.V1.Host.Storage.Scsi.ScsiLunMultipathPolicy MultipathPolicy {get;}                                     
RuntimeName          Property   System.String RuntimeName {get;}                                                                                                         
SerialNumber         Property   System.String SerialNumber {get;}                                                                                                        
Uid                  Property   System.String Uid {get;}                                                                                                                 
Vendor               Property   System.String Vendor {get;}                                                                                                              
VMHost               Property   VMware.VimAutomation.ViCore.Types.V1.Inventory.VMHost VMHost {get;}                                                                      
VMHostId             Property   System.String VMHostId {get;}                                                                                                           

How do i decypher which are VMFS and which are RDM?

0 Kudos
5 Replies
LucD
Leadership
Leadership

In my LUN report – datastore, RDM and node visibility post you'll find how list RDM per VMHost


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

internetrush1
Contributor
Contributor

Unfortunately that does not indicate UNUSED RDM luns, is there a way to do this?

0 Kudos
LucD
Leadership
Leadership

You mean LUNs that are not mounted on the ESXi host ? Or not attached ?

Or both ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
internetrush1
Contributor
Contributor

Ive castrated your script:

Get-Cluster | where-object {$_.name -match '049'} | Get-VM | Get-View | %{
$vm = $_
$vm.Config.Hardware.Device | where {$_.gettype().Name -eq "VirtualDisk"} | %{
  if("physicalMode","virtualmode" -contains $_.Backing.CompatibilityMode){
   write-host $_.Backing.LunUuid.Substring(10,32)
   write-host (Get-View $vm.Runtime.Host).Name.Split(".")[0] + "-" + $disk
   write-host $vm.Name + "/" + $_.DeviceInfo.Label
  }
}
}

From what i can gather, this returns only Luns that are attached to a VM with a backing of Physical or Virtual.

The luns i need are visible via the host storage configuration section; but they are not assigned to any VM's. They are simply ready for use.

From what i can tell, this script is only returning the RDM drives in use from VM's, is this the case? I will review to see if i can find a cluster with many unmounted RDM's, but at a glance im not sure if this is what i need.

What i need: List of Unused luns attached to host but not any vms

0 Kudos
LucD
Leadership
Leadership

That sounds painfull (for my script) :smileygrin:

Try this

$esx = Get-VMHost MyEsxi 
$dsSys
= Get-View $esx.Extensiondata.ConfigManager.DatastoreSystem
$dsSys
.QueryAvailableDisksForVmfs($null) |
Select
CanonicalName


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference