1 2 Previous Next 15 Replies Latest reply on Sep 24, 2012 5:04 AM by VgeekFreak

    Datastore capacity report

    peter79 Enthusiast

      Guys,

       

      I need a powershell script that will output the following to a csv file.

       

      The name of each datastore in vCenter, the capacity and amount of used space.

       

      Thanks, 

        • 1. Re: Datastore capacity report
          LucD Guru
          vExpertCommunity WarriorsUser Moderators

          Try something like this

           

          Get-Datastore | 
          Select Name,CapacityGB,@{N="UsedGB";E={"{0:f1}" -f ($_.CapacityGB - $_.FreeSpaceGB)}} | 
          Export-Csv .\report.csv -NoTypeInformation -UseCulture
          1 person found this helpful
          • 2. Re: Datastore capacity report
            peter79 Enthusiast

            Looks good but in the CSV file under usedGB all the figures have a minus before them.

            • 3. Re: Datastore capacity report
              LucD Guru
              Community WarriorsvExpertUser Moderators

              Strange, what does this show ?

              Is the FreeSpaceGB bigger than the CapacityGB ?

               

              Get-Datastore | 
              Select Name,CapacityGB,FreeSpaceGB | 
              Export-Csv .\report.csv -NoTypeInformation -UseCulture


              It could also be the error that was present PowerCLI before version 5.0.1.

              The CapacityGB and FreeSpaceGB were swapped.

              Are you usng PowerCLI 5.0.1 ?

              Do a

              Get-PowerCLIVersion
              • 4. Re: Datastore capacity report
                EdWilts Expert

                If it doesn't have to be Powershell but can be something a little less automated but more powerful, look at RVTools from http://robware.net/.  It's free and has everything you need and then some.

                • 5. Re: Datastore capacity report
                  peter79 Enthusiast

                  I'm using version 5.0 I've noticed that when I run the following command

                   

                  get-datastore | select name, CapacityGB, FreeSpaceGB

                   

                  I get the output I need but the figures under CapacityGB and FreeSpaceGB seem to be be reversed.  Is this a bug with PowerShell?

                  • 6. Re: Datastore capacity report
                    LucD Guru
                    Community WarriorsvExpertUser Moderators

                    Yes, that is the bug I mentioned in my previous answer.

                    Upgrade to PowerCLI 5.0.1, the bug is fixed in that release.

                    • 7. Re: Datastore capacity report
                      LucD Guru
                      vExpertCommunity WarriorsUser Moderators

                      Although I'm a big fan of Rob's tool, why do you claim it is 'more powerful' compared to PowerCLI ?

                      Just curious

                      • 8. Re: Datastore capacity report
                        EdWilts Expert

                        LucD wrote:

                         

                        Although I'm a big fan of Rob's tool, why do you claim it is 'more powerful' compared to PowerCLI ?

                        Just curious

                        OK, not more powerful than PowerCLI as a whole...  More powerful than a script that solves a single problem though and it's pretty fast since a lot of us already have it installed.  There's nothing in RVTools that you can't write yourself in PowerCLI.

                        • 9. Re: Datastore capacity report
                          peter79 Enthusiast

                          I'm upgrading  to the latest version of PowerCLI but I just realised I forgot to take something into account.  All our VM's use thin provisioned disks so I need to capture how much provisined space in on a datastore?

                          • 10. Re: Datastore capacity report
                            LucD Guru
                            User ModeratorsCommunity WarriorsvExpert

                            Try it like this

                             

                            Get-Datastore | 
                            Select Name,CapacityGB,
                                @{N="UsedGB";E={"{0:f1}" -f ($_.CapacityGB - $_.FreeSpaceGB)}},
                                @{N="ProvisionedGB";E={"{0:f1}" -f (($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB)}} |
                            Export-Csv .\report.csv -NoTypeInformation -UseCulture
                            
                            • 11. Re: Datastore capacity report
                              VgeekFreak Novice

                              Hi LuC,

                               

                              Adding to this, I need a list of VMs that are lying on those datastore along with datastore storage capacity stuff.

                               

                              Get-Datastore | 
                              Select Name,CapacityGB,@{N="UsedGB";E={"{0:f1}" -f ($_.CapacityGB - $_.FreeSpaceGB)}} | 
                              Export-Csv .\report.csv -NoTypeInformation -UseCulture
                              

                               

                               

                              Could you help, Thanks

                              • 12. Re: Datastore capacity report
                                jade_ Novice

                                expanding the example used:

                                 

                                 

                                Get-Datastore |
                                Select Name,CapacityGB, `
                                @{N="UsedGB";E={"{0:f1}" -f ($_.CapacityGB - $_.FreeSpaceGB)}},`
                                @{N="VMs";E={Get-VM -Datastore $_.name}} | `
                                Export-Csv .\report.csv -NoTypeInformation -UseCulture

                                 

                                Hope that helps :-)

                                 

                                J

                                • 13. Re: Datastore capacity report
                                  VgeekFreak Novice

                                  Hi Jade_

                                   

                                  Yes It does ! however the output is like

                                   

                                  Datastore name       Capacity          Used            VM names (all in one ROW)

                                   

                                  can we get it in Column ? Thanks again.

                                  • 14. Re: Datastore capacity report
                                    jade_ Novice

                                    Try this:

                                     

                                     

                                    $Datastores = Get-Datastore | Where {$_.tyype -like "VMFS"} | Sort Name
                                    ForEach ($Datastore in $Datastores) {
                                    $Row = "" | Select-Object Datastore, CapacityGB, FreeSpaceGB, UsedGB, VMs
                                    $Row.Datastore = $Datastore.name
                                    $Row.CapacityGB = [math]::round(($Datastore.CapacityGB),2)
                                    $Row.FreeSpaceGB = [math]::round(($Datastore.FreeSpaceGB),2)
                                    $Row.UsedGB = [math]::round((($Datastore.CapacityGB) - ($Datastore.FreeSpaceGB)),2)
                                    $i = 1
                                    ForEach ($VM in (Get-VM -Datastore $Datastore |sort name))
                                    {
                                               Add-Member -InputObject $Row -Name ("VMs" + $i) -Value $VM.Name -MemberType NoteProperty
                                               $i++
                                              }
                                        $Report += $Row
                                    }
                                    $report

                                     

                                     

                                    Thanks

                                     

                                    Jade

                                    1 2 Previous Next