Automation

 View Only
Expand all | Collapse all

Get RDM Details along with LUN id of multiple VMs

  • 1.  Get RDM Details along with LUN id of multiple VMs

    Posted Aug 28, 2021 08:33 AM

    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.

     



  • 2.  RE: Get RDM Details along with LUN id of multiple VMs

    Posted Aug 28, 2021 09:08 AM


  • 3.  RE: Get RDM Details along with LUN id of multiple VMs

    Posted Aug 28, 2021 10:33 AM

    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



  • 4.  RE: Get RDM Details along with LUN id of multiple VMs

    Posted Aug 28, 2021 10:38 AM

    That script you posted is not looking for RDM disks.



  • 5.  RE: Get RDM Details along with LUN id of multiple VMs
    Best Answer

    Posted Aug 28, 2021 10:52 AM

    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
    


  • 6.  RE: Get RDM Details along with LUN id of multiple VMs

    Posted Aug 28, 2021 11:02 AM

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



  • 7.  RE: Get RDM Details along with LUN id of multiple VMs

    Posted Aug 28, 2021 12:23 PM

    No, this version looks at all the VMs



  • 8.  RE: Get RDM Details along with LUN id of multiple VMs

    Posted Aug 28, 2021 01:59 PM

    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.



  • 9.  RE: Get RDM Details along with LUN id of multiple VMs

    Posted Aug 28, 2021 02:27 PM

    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 |


  • 10.  RE: Get RDM Details along with LUN id of multiple VMs

    Posted Aug 30, 2021 04:48 AM

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



  • 11.  RE: Get RDM Details along with LUN id of multiple VMs

    Posted Sep 08, 2022 01:46 PM

    Hi ,

     

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

    Thanks



  • 12.  RE: Get RDM Details along with LUN id of multiple VMs

    Posted Sep 09, 2022 05:40 AM

    Isn't that what the SCSI_ID property does?



  • 13.  RE: Get RDM Details along with LUN id of multiple VMs

    Posted Sep 09, 2022 12:11 PM

    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.



  • 14.  RE: Get RDM Details along with LUN id of multiple VMs

    Posted Sep 09, 2022 12:29 PM

    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.



  • 15.  RE: Get RDM Details along with LUN id of multiple VMs

    Posted Sep 09, 2022 12:55 PM

    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.

     

     

     

     



  • 16.  RE: Get RDM Details along with LUN id of multiple VMs

    Posted Sep 09, 2022 01:01 PM

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

    if that works for you, great