1 2 3 4 Previous Next 50 Replies Latest reply on Jul 18, 2017 6:39 AM by LucD

    list disks rdm with powershell

    Josito Novice

       

      Hello ,

       

       

      i like how lists disk rdm of a vm .Command get-hardisk give me location vmdk , capacity , but i want more informatation disks RDMs

       

       

      Por example , i want to list imformation like vmhba 1:0:9:0 , SCSI (2:1) , etc  for each disk . 

       

       

      Someone can gime some help

       

       

      Thanks

       

       

        • 1. Re: list disks rdm with powershell
          LucD Guru
          vExpertCommunity WarriorsUser Moderators

          This gives the devicename of each RDM disk for each vm.

          $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"){
                   $row = "" | select VMName, HDDeviceName, HDFileName
                    $row.VMName = $vm.Name
                   $row.HDDeviceName = $dev.Backing.DeviceName
                   $row.HDFileName = $dev.Backing.FileName
                   $report += $row
                 }
               }
            }
          }
          $report
          

           

          • 2. Re: list disks rdm with powershell
            munizaba@gmail.com Enthusiast

            Hi LucD,

             

             

            Can you please check attached Script since is not producing any result.

             

             

            Regards,

            • 3. Re: list disks rdm with powershell
              LucD Guru
              vExpertCommunity WarriorsUser Moderators

              Could it be that there are no raw disks ?

              Perhaps try without the test for "physicalMode".

              $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"){ 
                                            $row = "" | select VMName, HDDeviceName, HDFileName 
                                            $row.VMName = $vm.Name 
                                            $row.HDDeviceName = $dev.Backing.DeviceName 
                                            $row.HDFileName = $dev.Backing.FileName 
                                                 $report += $row 
                                       }      
              #                    } 
                             } 
              } 
              $report
              

               

              • 4. Re: list disks rdm with powershell
                munizaba@gmail.com Enthusiast

                 

                Thanks mate, is working now:

                 

                 

                 

                 

                 

                $report = @()

                 

                 

                $vms = Get-VM | Get-View

                 

                 

                foreach($vm in $vms) {

                 

                 

                foreach($dev in $vm.Config.Hardware.Device) {

                 

                 

                if(($dev.gettype()).Name -eq "VirtualDisk") {

                 

                 

                $row = "" | select VMName, HDDeviceName, HDFileName

                 

                 

                $row.VMName = $vm.Name

                 

                 

                $row.HDDeviceName = $dev.Backing.DeviceName

                 

                 

                $row.HDFileName = $dev.Backing.FileName

                 

                 

                $report += $row

                 

                 

                 

                 

                 

                }

                 

                 

                }

                 

                 

                }

                 

                 

                $report

                 

                 

                 

                 

                 

                • 5. Re: list disks rdm with powershell
                  LucD Guru
                  vExpertUser ModeratorsCommunity Warriors

                  Just came to realise that RDMs come in 2 flavours, physical and virtual.

                  Since I only tested for physical and your RDMs are probably in virtual compatibility mode they didn't show.

                   

                  This script should only show RDMs but for both compatibility modes

                  $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, HDDeviceName, HDFileName, HDMode
                            $row.VMName = $vm.Name
                           $row.HDDeviceName = $dev.Backing.DeviceName
                           $row.HDFileName = $dev.Backing.FileName
                           $row.HDMode = $dev.Backing.CompatibilityMode
                           $report += $row
                         }
                       }
                    }
                  }
                  $report
                  

                   

                  • 6. Re: list disks rdm with powershell
                    brekus Hot Shot

                    This script is great. Just as an FYI, instead of looking for disks that are virtual or physical mode, I looked for disks that were not equal to flat.

                    • 7. Re: list disks rdm with powershell
                      gboskin Hot Shot

                       

                      Hi all ....

                       

                       

                      I was wondering how to add the RDM size to this table ??

                       

                       

                       

                       

                       

                      Kind regards

                       

                       

                       

                       

                       

                      • 8. Re: list disks rdm with powershell
                        LucD Guru
                        vExpertUser ModeratorsCommunity Warriors

                        The answer is in  Get RDM size

                        • 9. Re: list disks rdm with powershell
                          emmar Expert

                           

                          Hi,

                           

                           

                          This script is great is there a way to get it to output what ESX host the VMs are on?? Is there a property for the host within the $vm object??? something like $vm.Host??

                           

                           

                          Thanks

                           

                           

                          Emma

                           

                           

                          • 10. Re: list disks rdm with powershell
                            LucD Guru
                            vExpertUser ModeratorsCommunity Warriors

                            Yes, the VirtualMachine object contains, under the Runtime.Host property, a MoRef to the host on which the VM is running or assigned.

                            The script could then be something like this:

                            $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
                                      $row.VMName = $vm.Name
                                     $row.VMHost = (Get-View $vm.Runtime.Host).Name
                                     $row.HDDeviceName = $dev.Backing.DeviceName
                                     $row.HDFileName = $dev.Backing.FileName
                                     $row.HDMode = $dev.Backing.CompatibilityMode
                                       $row.HDSize = $dev.CapacityInKB
                                     $report += $row
                                   }
                                 }
                              }
                            }
                            $report
                            

                             

                            • 11. Re: list disks rdm with powershell
                              emmar Expert

                               

                              Thanks LucD

                               

                               

                              Thats great! And a useful link so hopefully i can work more out for myself!

                               

                               

                              E

                               

                               

                              • 12. Re: list disks rdm with powershell
                                AlbertWT Master

                                 

                                thanks man, this is such a useful script !

                                 

                                 

                                Kind Regards,

                                AWT

                                • 13. Re: list disks rdm with powershell
                                  Tom Cronin Expert
                                  vExpert

                                   

                                  Does anyone know how to add the device name to the output?  For example, instead of just the vmhba notitation, can you also get something like this: 

                                   

                                   

                                  EMC Fibre Channel Disk (naa.60060480000190100744533031393736)

                                   

                                   

                                  Thanks!

                                   

                                   

                                  Tom Cronin, VCP, VMware vExpert 2009 - Co-Leader Buffalo, NY VMUG

                                   

                                   

                                  • 14. Re: list disks rdm with powershell
                                    LucD Guru
                                    User ModeratorsvExpertCommunity Warriors

                                    I suspect you are after the DisplayName as it's called in the SDK Reference.

                                    Try this script, the DisplayName has been added.

                                    $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
                                    

                                     

                                    1 person found this helpful
                                    1 2 3 4 Previous Next