8 Replies Latest reply on Aug 22, 2019 10:24 PM by LucD

    Script for LUN Utilization in CSV format

    CoolonVsphere Novice

      Hi All

       

      We are looking for Script which will provide lun Utilization in below format.

      This will help in provide lun details like vmfs type/ last update /Capacity of Lun/Capacity of lun(inGB) /Free space/Used space and % of lun utilization

      All luns are managed by our centrally vcenter server. I am not expert in powercli hopefully from this forum i Will get assistance :-)

       

         

      LUN Identification NameTypeLast UpdateCapacity (GB)Free (GB)Used Space(GB)% of LUN Utilization
      LUN01_vol01VMFS33/6/2017 1:30:52 PM1863.68901.04962.6451.65
      LUN02_vol01VMFS33/6/2017 1:30:51 PM1536597.64938.3661.09

      Thanks in Advance

       

      PS

        • 1. Re: Script for LUN Utilization in CSV format
          LucD Guru
          User ModeratorsCommunity WarriorsvExpert

          Not sure what you want to see under Last Update.

           

          Get-Datastore |

          Select Name,

              @{N='Type';E={"$($_.Type)$($_.ExtensionData.Info.Vmfs.MajorVersion)"}},

              @{N='CapacityGB';E={[math]::Round($_.CapacityGB)}},

              @{N='FreeSpaceGB';E={[math]::Round($_.FreeSpaceGB)}},

              @{N='UsedSpaceGB';E={[math]::Round($_.CapacityGB - $_.FreeSpaceGB,1)}},

              @{N='% of LUN Utilization';E={[math]::Round(($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB * 100,1)}}

           

          1 person found this helpful
          • 2. Re: Script for LUN Utilization in CSV format
            CoolonVsphere Novice

            Thanks for LuCD

            Really appreciate for the quick reply ...

             

            Script is running but not sure where its getting saved in csv format. (searced in desktop and C drive too not found the CSV output)

             

            and also if we can add few more columns like  next to   @{N='Type';E={"$($_.Type)$($_.ExtensionData.Info.Vmfs.MajorVersion)"}}

             

              

            NameIdentifierPath IDLUN
            DELL Fibre Channel Disk (naa.690b11c0003d8d6600000887519c23fa)naa.690b11c0003d8d6600000887519c23favmhba1:C0:T0:L21101
            • 3. Re: Script for LUN Utilization in CSV format
              LucD Guru
              User ModeratorsvExpertCommunity Warriors

              This is with the Identifier field included, and an export to a CSV.

               

              Get-Datastore |

              Select Name,

                  @{N='Type';E={"$($_.Type)$($_.ExtensionData.Info.Vmfs.MajorVersion)"}},

                  @{N='CapacityGB';E={[math]::Round($_.CapacityGB)}},

                  @{N='FreeSpaceGB';E={[math]::Round($_.FreeSpaceGB)}},

                  @{N='UsedSpaceGB';E={[math]::Round($_.CapacityGB - $_.FreeSpaceGB,1)}},

                  @{N='% of LUN Utilization';E={[math]::Round(($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB * 100,1)}},

                  @{N='Identifier';E={$_.ExtensionData.Info.Vmfs.Extent[0]}} |

              Export-Csv report.csv -NoTypeInformation -UseCulture

               

              The Path Id for a datastore can be different per VMHost.

              How will you display that? This is for datastores that are shared between multiple VMHosts.

              • 4. Re: Script for LUN Utilization in CSV format
                CoolonVsphere Novice

                Thanks now csv is generated. You are right Path Id for a datastore can be different per VMHost. So this one we donot required.

                can it possible to have datastore LUN number  all added in new Column.

                1 person found this helpful
                • 5. Re: Script for LUN Utilization in CSV format
                  LucD Guru
                  User ModeratorsCommunity WarriorsvExpert

                  I'm afraid the LUN number can also be different per VMHost.

                  The only unique value is the Identifier afaik.

                  • 6. Re: Script for LUN Utilization in CSV format
                    RAJ_RAJ Expert
                    vExpert

                    Hi ,

                     

                    We can remove the Identifier  also  or  is it will affect on something ?

                     

                     

                    Like below

                     

                    Get-Datastore |

                    Select Name,

                        @{N='Type';E={"$($_.Type)$($_.ExtensionData.Info.Vmfs.MajorVersion)"}},

                        @{N='CapacityGB';E={[math]::Round($_.CapacityGB)}},

                        @{N='FreeSpaceGB';E={[math]::Round($_.FreeSpaceGB)}},

                        @{N='UsedSpaceGB';E={[math]::Round($_.CapacityGB - $_.FreeSpaceGB,1)}},

                        @{N='% of LUN Utilization';E={[math]::Round(($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB *100,1)}} |

                        Export-Csv report.csv -NoTypeInformation -UseCulture

                    RAJESH RADHAKRISHNAN
                    VCA -DCV/WM/Cloud,VCP 5 - DCV/DT/CLOUD, ,VCP6-DCV, EMCISA,EMCSA,MCTS,MCPS,BCFA
                    https://ae.linkedin.com/in/rajesh-radhakrishnan-76269335
                    Mark my post as "helpful" or "correct" if I've helped resolve or answered your query!
                    • 7. Re: Script for LUN Utilization in CSV format
                      davejohn7 Lurker

                      Hi LucD,

                       

                      I would like to get these reports in mail. Is it possible ??

                      • 8. Re: Script for LUN Utilization in CSV format
                        LucD Guru
                        Community WarriorsUser ModeratorsvExpert

                        Sure, try like this

                         

                        $report = Get-Datastore |

                        Select Name,

                        @{N = 'Type'; E = { "$($_.Type)$($_.ExtensionData.Info.Vmfs.MajorVersion)" } },

                        @{N = 'CapacityGB'; E = { [math]::Round($_.CapacityGB) } },

                        @{N = 'FreeSpaceGB'; E = { [math]::Round($_.FreeSpaceGB) } },

                        @{N = 'UsedSpaceGB'; E = { [math]::Round($_.CapacityGB - $_.FreeSpaceGB, 1) } },

                        @{N = '% of LUN Utilization'; E = { [math]::Round(($_.CapacityGB - $_.FreeSpaceGB) / $_.CapacityGB * 100, 1) } }

                         

                        $sMail = @{

                           To = 'me@domain'

                           From = 'report@domain'

                           Subject = 'Datastore Report'

                           SmtpServer = 'mail.domain'

                           Body = $report | ConvertTo-Html | Out-String

                           BodyAsHtml = $true

                        }

                        Send-MailMessage @sMail

                        1 person found this helpful
                        • 9. Re: Script for LUN Utilization in CSV format
                          AlbertWT Master

                          Is there any reason why the Identifier column is only showing "

                          VMware.Vim.HostScsiDiskPartition

                          " as the result ?

                          • 10. Re: Script for LUN Utilization in CSV format
                            LucD Guru
                            vExpertCommunity WarriorsUser Moderators

                            Try changing that line to

                             

                            @{N='Identifier';E={$_.ExtensionData.Info.Vmfs.Extent[0].DiskName}} |

                            1 person found this helpful
                            • 11. Re: Script for LUN Utilization in CSV format
                              AlbertWT Master

                              Thank you Luc, it is working as expected :-)

                              • 12. Re: Script for LUN Utilization in CSV format
                                davejohn7 Lurker

                                Hey LucD,

                                 

                                I would like to know where to run this script.

                                 

                                Hope i need to run it in a server which has access to the Vcentre ??

                                 

                                Do mention me where to run it ? I'm from storage background and because we don't have any specifc SNMP to monitor the LUN utilization, we would like to have these scripts to get the LUN utilization !! So kindly get back to me on this.

                                • 13. Re: Script for LUN Utilization in CSV format
                                  LucD Guru
                                  Community WarriorsvExpertUser Moderators

                                  Yes, you can run the script on any host that can connect (Connect-VIServer) to the vCenter.

                                  It doesn't really matter if it is a workstation or a server.

                                  The host where you run the script, needs to have PowerShell and the VMware PowerCLI modules installed.