PowerCLI

 View Only
  • 1.  List VM RDM Information Including LUN Number

    Posted Sep 14, 2012 02:26 PM

    Hi,

    Sorry... I have searched and searched to try to get a script that listed all VM's RDM information and LUN number but nothing quite matched my requirement. I have hacked some code together which works but I am sure there must be a more efficient way to report this information (the script takes a very long time to complete)?

    $result = @()
    $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, Host, LUNID, HDLabel, HDFileName, Mode
                if($dev.Backing.CompatibilityMode -eq "physicalMode"){
                   $row.Mode = "Physical RDM"
                }
                else {
                   $row.Mode = "Virtual RDM"
                }
                $row.HDFileName = $dev.Backing.FileName
                $row.VMName = $vm.Name
                $getvm = Get-VM $row.VMName
                $row.Host = $getvm.VMHost
                $row.HDLabel = $dev.DeviceInfo.Label

                $Disk = Get-VM $row.VMName | Get-HardDisk | Where {$_.FileName -eq $row.HDFileName}
                $Lun = Get-SCSILun $Disk.SCSICanonicalName -VMHost $row.Host
                $row.LUNID = $Lun.RuntimeName.Substring($Lun.RuntimeName.LastIndexof(“L”)+1)
                $result += $row
             }
          }
       }
    }
    $result

    Again, sorry if this does exist somewhere but if someone could point me to it, or amend this to be cleaner and quicker, it would be greatly appreciated.

    Many thanks



  • 2.  RE: List VM RDM Information Including LUN Number

    Posted Sep 14, 2012 04:22 PM

    The easiest thing to change would be how many time you do your Get-VM call....each time you do that it has to go to the server to retrieve that data.

    What I would do is just change your first few lines a bit

    $vms = Get-VM
    foreach($vm in $vms){
       foreach($dev in $vm.extensiondata.Config.Hardware.Device){

    ......

    Now later on in your script you can simply use $vm instead of the Get-VM call each time. Doing a $vm.extensiondata gets you the same info as if you did a $vm | Get-View

    Hope this helps



  • 3.  RE: List VM RDM Information Including LUN Number

    Posted Sep 17, 2012 01:18 PM

    Flock,

    You might want to check the script Luc Dekens wrote in this thread: http://communities.vmware.com/message/1232579#1232579

    It's called RDM-report.ps1 :smileyhappy: