13 Replies Latest reply on Sep 26, 2020 7:39 AM by Narayanan_5245

    PowerCli to pull RDM info

    justinsmith Enthusiast

      I use the following script to pull matrix from all my vCenter's. We have some RDM's that I want to capture in this as well... is it doable?

       

      When I say capture... Im looking to pull the # of RDM's as well as total space being used by them.

       

       

      "Total Datacenters: $(@(Get-Datacenter).Count)"
      "Total Clusters: $(@(Get-Cluster).Count)"
      "Total ESX Hosts: $(@(Get-VMHost).Count)"
      "Total VM's: $(@(Get-VM).Count)"
      "Total Templates: $(@(Get-Template).Count)"
      "Total LUN Datastores: $(@(Get-Datastore).Count)"
      $TotalDatastoresCapacityMB = 0
      Get-Datastore | ForEach-Object { $TotalDatastoresCapacityMB += $_.CapacityMB }
      $TotalDatastoresCapacityGb = $TotalDatastoresCapacityMB/1024
      "Total Size of LUN Datastores in GB: $TotalDatastoresCapacityGb"
      
        • 1. Re: PowerCli to pull RDM info
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          Sure, that is doable.

          Try something like this

           

          Get-VM | Get-HardDisk | 
          where {"RawPhysical","RawVirtual" -contains $_.DiskType} | 
          Select
          @{N="VM";E={$_.Parent.Name}},Name,ScsiCanonicalName
          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: PowerCli to pull RDM info
            justinsmith Enthusiast

            Heres the output I get when I add that line...

             

             

            Total Datacenters: 1
            Total Clusters: 2
            Total ESX Hosts: 20
            Total VM's: 1024
            Total Templates: 38
            Total LUN Datastores: 55
            
            VM                         Name                       ScsiCanonicalName
            --                         ----                       -----------------
            VM1                 Hard disk 3                naa.60a980006465647448...
            VM2                Hard disk 4                naa.60a980006465647448...
            

             

            Im looking for it to basically get me the number of VM's that have RDM's and the storage size allocated to them.... I dont need the iSCSI name either. just VM count and RDM size in GB's (preferably)

            • 3. Re: PowerCli to pull RDM info
              LucD Guru
              User ModeratorsCommunity WarriorsvExpert

              Ok, then try it like this

               

              $rdms = Get-VM | Get-HardDisk | where {"RawPhysical","RawVirtual" -contains $_.DIskType}
              "VM with RDM: $(($rdms | Sort-Object -Property {$_.Parent.Name} -Unique).Count)" 
              "Total RDM size GB $($rdms | Measure-Object -Property CapacityGB -Sum | Select -ExpandProperty Sum)"
              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: PowerCli to pull RDM info
                justinsmith Enthusiast

                Worked great....

                 

                Im assuming that based on the script I pasted, that the Total RDM size is in ADDITION to the Total size of LUN Datastores, right?

                • 5. Re: PowerCli to pull RDM info
                  LucD Guru
                  Community WarriorsUser ModeratorsvExpert

                  Correct, for the Total RDM size the script adds the capacity of the LUNs used for RDMs.

                  The LUNs used for datastores are not in there.

                   

                  Note, there is a small overhead, in that a RDM disk also has a VMDK header file that is stored with the files of the VM on a datastore.

                  But the size of these RDM header VMDK files is very small.

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 6. Re: PowerCli to pull RDM info
                    justinsmith Enthusiast

                    Is there a way to change the GB to TB in the "Total RDM size in GB"

                     

                    I can change it in the LUN side, but not sure if CapacityGB can be changed at all....

                    • 7. Re: PowerCli to pull RDM info
                      LucD Guru
                      User ModeratorsvExpertCommunity Warriors

                      Try like this

                       

                      $rdms = Get-VM | Get-HardDisk | where {"RawPhysical","RawVirtual" -contains $_.DIskType}
                      "VM with RDM: $(($rdms | Sort-Object -Property {$_.Parent.Name} -Unique).Count)" 
                      "Total RDM size TB $(($rdms | Measure-Object -Property CapacityGB -Sum | Select -ExpandProperty Sum)/1KB)" 
                      
                      Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                      • 8. Re: PowerCli to pull RDM info
                        justinsmith Enthusiast

                        It didnt actually divide the number.

                         

                        Here's the output:

                         

                        Total RDM size TB 91623.8641958237/1KB

                         

                         

                        With this being the script:

                         

                         

                        $rdms = Get-VM | Get-HardDisk | where {"RawPhysical","RawVirtual" -contains $_.DIskType}
                        "VM with RDM: $(($rdms | Sort-Object -Property {$_.Parent.Name} -Unique).Count)" 
                        "Total RDM size TB $(($rdms | Measure-Object -Property CapacityGB -Sum | Select -ExpandProperty Sum))/1KB"
                        
                        • 9. Re: PowerCli to pull RDM info
                          LucD Guru
                          Community WarriorsvExpertUser Moderators

                          The clsoing parenthesis was at the wrong position, I corrected it above.

                          Try again please.

                          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                          • 10. Re: PowerCli to pull RDM info
                            justinsmith Enthusiast

                            Perfect!

                            • 11. Re: PowerCli to pull RDM info
                              yosingh Novice

                              Hi @LucD,

                              You are awesome, can we also get only shared RDM details (only RDMs attached to the clustered VMs)?

                              • 12. Re: PowerCli to pull RDM info
                                LucD Guru
                                User ModeratorsvExpertCommunity Warriors

                                Sure, try something like this

                                 

                                Get-VM | Get-HardDisk |

                                where {"RawPhysical","RawVirtual" -contains $_.DiskType -and

                                       "Physical","Virtual" -contains (Get-ScsiController -HardDisk $_).BusSharingMode} |

                                Select @{N='VM';E={$_.Parent.Name}},

                                    Name,

                                    FileName,

                                    CapacityGB,

                                    DiskType,

                                    ScsiCanonicalName,

                                    @{N='BusSharing';E={(Get-ScsiController -HardDisk $_).BusSharingMode}}

                                 

                                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                • 13. Re: PowerCli to pull RDM info
                                  Narayanan_5245 Enthusiast

                                  Hi LuCD,

                                   

                                  Sorry for opening the old thread. Can you please help to suggest if we can able to include the SCSI controller (LSI or VMware paravirtual) and the RDM disk bus sharing mode (No sharing or Multiwriter) as well?

                                   

                                  Thank you

                                   

                                  Regards

                                  Narayanan.