VMware Cloud Community
system_noida
Enthusiast
Enthusiast
Jump to solution

Get RDM Details along with LUN id of multiple VMs

Hi All,

Please can some one help me. I need to fetch the report of RDM LUNs attached to multiple VMs along with LUN ID. I have approx 400 VMs. I am trying to run the below script which is working but 1). Its not giving me the LUN ID and 2). I am not able to run it for multiple VMs. Please can you help me with this. really appreciate....

$DiskInfo= @()
foreach ($VMview in Get-VM SERVER01 | Get-View){
foreach ($VirtualSCSIController in ($VMView.Config.Hardware.Device | where {$_.DeviceInfo.Label -match "SCSI Controller"})) {
foreach ($VirtualDiskDevice in ($VMView.Config.Hardware.Device | where {$_.ControllerKey -eq $VirtualSCSIController.Key})) {
$VirtualDisk = "" | Select VMname, SCSIController, DiskName, SCSI_ID, DeviceName, DiskFile, DiskSize
$VirtualDisk.VMname = $VMview.Name
$VirtualDisk.SCSIController = $VirtualSCSIController.DeviceInfo.Label
$VirtualDisk.DiskName = $VirtualDiskDevice.DeviceInfo.Label
$VirtualDisk.SCSI_ID = "$($VirtualSCSIController.BusNumber) : $($VirtualDiskDevice.UnitNumber)"
$VirtualDisk.DeviceName = $VirtualDiskDevice.Backing.DeviceName
$VirtualDisk.DiskFile = $VirtualDiskDevice.Backing.FileName
$VirtualDisk.DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB / 1GB
$DiskInfo += $VirtualDisk
}}}
$DiskInfo | sort VMname, Diskname | Export-Csv -Path 'F:DiskInfo.csv'

 

This is the result it gives to me.

system_noida_0-1630139524953.png

 

Thanks.

 

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If you want to find all RDM, you could do something like this

Get-VM -PipelineVariable vm |
Get-HardDisk -DiskType "RawVirtual", "RawPhysical" -PipelineVariable hd |
ForEach-Object -Process {
  New-Object -TypeName PSObject -Property ([ordered]@{
    VM = $vm.Name
    SCSIController = (Get-ScsiController -HardDisk $hd).Name
    DiskName = $hd.Name
      SCSI_ID = (Get-ScsiLun -CanonicalName $hd.ScsiCanonicalName -VmHost $vm.VMHost).RuntimeName.Split(':')[-1].TrimStart('L')
    DeviceName = $hd.ScsiCanonicalName
    DiskFile = $hd.FileName
    DiskSizeGB = $hd.CapacityGB
  })
} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


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

View solution in original post

Reply
0 Kudos
15 Replies
LucD
Leadership
Leadership
Jump to solution

Reply
0 Kudos
system_noida
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

That one is i believe for the devices if you have already the device lits. My requirement is here that I am having 400 VMs and I need to check whether those 400 VMs are having any RDM LUNs attached. if yes then fetch the details in a CSV along with the LUN ID.

 

If you please can help with the parameter  I need to add in above existing script.

Thanks

Tags (1)
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That script you posted is not looking for RDM disks.


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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you want to find all RDM, you could do something like this

Get-VM -PipelineVariable vm |
Get-HardDisk -DiskType "RawVirtual", "RawPhysical" -PipelineVariable hd |
ForEach-Object -Process {
  New-Object -TypeName PSObject -Property ([ordered]@{
    VM = $vm.Name
    SCSIController = (Get-ScsiController -HardDisk $hd).Name
    DiskName = $hd.Name
      SCSI_ID = (Get-ScsiLun -CanonicalName $hd.ScsiCanonicalName -VmHost $vm.VMHost).RuntimeName.Split(':')[-1].TrimStart('L')
    DeviceName = $hd.ScsiCanonicalName
    DiskFile = $hd.FileName
    DiskSizeGB = $hd.CapacityGB
  })
} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


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

Reply
0 Kudos
system_noida
Enthusiast
Enthusiast
Jump to solution

Hi LucD, Do I need to input the csv file of my 400 VMs pls ?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, this version looks at all the VMs


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

Reply
0 Kudos
system_noida
Enthusiast
Enthusiast
Jump to solution

LucD , I did checked it and its working perfectly , Kudos to you.  👍🙂

Is there any chance we can input the CSV files for only the VMs for which we are looking for pls. Thanks.

Tags (1)
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Assuming the column with names of the VMs is VMName, you can replace the 1st line with

Get-VM -Name (Import-Csv -Path .\vmnames.csv -UseCulture).VMName -PipelineVariable vm |


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

Reply
0 Kudos
system_noida
Enthusiast
Enthusiast
Jump to solution

Thank you very much mate!, you really saved my day.

Tags (1)
Reply
0 Kudos
system_noida
Enthusiast
Enthusiast
Jump to solution

Hi @LucD ,

 

Please can you help me with adding SCSI UnitNUmber in this script, like 1:1, or 2:2 or SCSI1:1, SCSI1:2.

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Isn't that what the SCSI_ID property does?


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

Reply
0 Kudos
system_noida
Enthusiast
Enthusiast
Jump to solution

SCSI_ID giving the LUN ID , I need to get the HDD SCSI port number also . like HDD1 connected to SCSI Controller 2 but on which unitnumber.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That information is coming from inside the Guest OS.
There is no foolproof method that I know of that can map VMDK to Guest OS HDD.


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

Reply
0 Kudos
system_noida
Enthusiast
Enthusiast
Jump to solution

I added below code in the script code and I am able to get the Unit Number of the SCSI Disk connected to.

 

UnitNumber = "$($VirtualSCSIController.BusNumber) $($VirtualDiskDevice.UnitNumber)"

system_noida_0-1662727947450.png

In this screen shot the HDD 4 is connected to SCSI2:25 and same with other HDD too.

Is that correct one what I have added in the script. I have verified manually on VMs settings and its matching.

 

 

 

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is not the HDD from inside the Guest OS, that is the VMDK ID

if that works for you, great


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