VMpros.nl
new1234.jpg
Home > VMware > VMware: List all RDM disks in Hosts and Virtual Machines via PowerCLI

VMware: List all RDM disks in Hosts and Virtual Machines via PowerCLI

To prepare a SAN to SAN migration I need to list all virtual machines with RAW Device Mappings, I found a very nice script at Pastebin (I’ve this you’re script, please comment to receive the credits), the script:

$report = @()
$vms = 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

image

Ps. the script can take a while to list…

avatar

sanderdaems

Sander Daems is founder and author of this blog and working as a Infrastructure Consultant by IT-Value. Sander has over 9 years experience in IT, primary focus: virtualization, storage and SBC

More Posts - Website

Follow Me:
TwitterLinkedIn

Categories: VMware Tags: , , , , ,
  1. avatar
    Ivan
    August 28th, 2011  (Quote) at 12:33  (Quote) | #1

    Wonderful, great script. I’m also busy with NetApp to NetApp migration

    Cheers!!

  2. avatar
    dianilka
    August 30th, 2011  (Quote) at 20:56  (Quote) | #2

    Can you export this to .csv?

  3. September 15th, 2011  (Quote) at 15:12  (Quote) | #3

    @dianilka
    The only thing you have to do, to export it to CSV is to add | Export-CSV -NoTypInformation .csv

    That’s all.

  4. avatar
    Matheen
    September 15th, 2011  (Quote) at 15:43  (Quote) | #4

    Do I need to simply copy the full script above and paste it into my Powercli? I did and nothing seems to happen?

  5. September 16th, 2011  (Quote) at 08:14  (Quote) | #5

    Hi Matheen, the best thing you can do is copy the content of the script to notepad, then you save the file as “list_rdm.ps1″

    Once you opened PowerCLI and connected vCenter server or host you can run the list_rdm.ps1 and you will get the result

  6. avatar
    venkat
    November 3rd, 2011  (Quote) at 09:55  (Quote) | #6

    hi all,

    forgive me if i am asking worst, how can i run the above script from power cli, where i can learn about scripting from the scratch.

    thanks in advance.

  7. avatar
    VM-WOLV
    November 17th, 2011  (Quote) at 17:19  (Quote) | #7

    What is the command for exporting to a given location, like to a NAS or file share location?

  8. avatar
    VM-WOLV
    November 17th, 2011  (Quote) at 21:43  (Quote) | #8

    Please disregard last post, I figured it out on my own

  9. avatar
    tom
    February 7th, 2012  (Quote) at 00:03  (Quote) | #9

    I run this and nothing works for me. I even try to do an echo $report and nada. It seems like it runs, but no output. Any Ideas?

  10. avatar
    Daoud Shariff
    October 3rd, 2012  (Quote) at 03:27  (Quote) | #10

    Search for a file named report. Or change the first line and the last two lines in the script to “report.tom”. Then, after the script runs, search for “report.tom”.

    OR
    add this line to the end of the script:
    Export-CSV -report.tom.csv

    OR
    copy the script into Kornshell, CShell, Bourne Shell or BASH or otherwise,as an executable unix script. Then invoke it from the command line by just typing in ‘report.tom’ . It will effectively be in an executable format I.E. (report.tom.exe). And May The Force Be With you!

  11. avatar
    Daoud Shariff
    October 3rd, 2012  (Quote) at 03:35  (Quote) | #11

    Actually, skip that last suggestion, unless you are running on a Unix box.

  12. avatar
    SamB
    May 2nd, 2013  (Quote) at 03:36  (Quote) | #12

    If Exporting to CSV, how do you write the Output accross a csv sheet.

  13. avatar
    oussama
    February 20th, 2014  (Quote) at 12:12  (Quote) | #13

    great script. verry usefull

  1. No trackbacks yet.