10 Replies Latest reply on Feb 15, 2020 10:10 AM by vmk2014

    Storage usage for a particular data store

    vmk2014 Expert

      Hi All,

       

      I'm looking to determine the storage usage for a particular data store in the below format (see the attachment)

       

      Data store NameTotal CapacityUsed SpaceUsed %Available SpaceRemaining %Total VM'sVM Used SpaceOrphan Disk SpaceSnapshot SpaceTemplate Space

       

       

      is it possible to pull the above information from power cli script ?

       

      Thanks

      V

        • 1. Re: Storage usage for a particular data store
          LucD Guru
          vExpertCommunity WarriorsUser Moderators

          The following will give you all fields, except for the orphaned data.

          The reason is that determining what is orphaned data or not is hard to automate.

          That' s also the reason why my script to discover orphaned files and folders doesn't do deletes automatically.

           

          Get-Datastore |

          Select Name,CapacityGB,

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

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

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

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

              @{N='TotalVM';E={$_.ExtensionData.Vm.Count}},

              @{N='VMUsedGB';E={[math]::Round((Get-VM -Datastore $_ | Measure-Object -Property UsedSpaceGB -Sum).Sum)}},

              @{N='SnapshotGB';E={[math]::Round((Get-vm -Datastore $_ | Get-Snapshot | Measure-Object -Property SizeGB -Sum).Sum)}}

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Storage usage for a particular data store
            vmk2014 Expert

            Hi LucD,

             

            There are 2 things, i'm looking to add here. Can we get the for data store usage for a specific data store name WIndows_PowerMax_0000 or for all Powermax data store usage

            WindowsVMax_0000  or  for all Vmax data store usage ? Also total size at the end of report like  Total used space is 79 TB and free space available Total is 60 TB in every column.

             

            Thanks

            V

             

             

            • 3. Re: Storage usage for a particular data store
              LucD Guru
              Community WarriorsvExpertUser Moderators

              You could do something like this.

              By changing the content of $dsName you can get the report for 1 datastore, a selection of datastores or all datastores

               

              #$dsName = 'WIndows_PowerMax_0000'

              #$dsName = '*PowerMax*'

              $dsName = '*'

              $report = Get-Datastore -Name $dsName |

              Select Name,

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

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

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

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

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

                  @{N='TotalVM';E={$_.ExtensionData.Vm.Count}},

                  @{N='VMUsedGB';E={[math]::Round((Get-VM -Datastore $_ | Measure-Object -Property UsedSpaceGB -Sum).Sum)}},

                  @{N='SnapshotGB';E={[math]::Round((Get-vm -Datastore $_ | Get-Snapshot | Measure-Object -Property SizeGB -Sum).Sum)}}


              $report += '' | Select @{N='Name';E={'Total'}},

                  @{N='CapacityGB';E={($report | Measure-Object -Property CapacityGB -Sum).Sum}},

                  @{N='UsedGB';E={}},

                  @{N='UsedGB%';E={}},

                  @{N='FreeSpaceGB';E={($report | Measure-Object -Property FreeSpaceGB -Sum).Sum}},

                  @{N='FreeSpaceGB%';E={}},

                  @{N='TotalVM';E={}},

                  @{N='VMUsedGB';E={}},

                  @{N='SnapshotGB';E={}}

              $report

               

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: Storage usage for a particular data store
                vmk2014 Expert

                Sorry, it still gives the same output as earlier script.

                 

                #$dsName = 'WIndows_PowerMax_*'

                #$dsName = '*PowerMax*'

                 

                Data store name starts like Windows_powermax3441/powermax4432 etc, hence i used astrix at the end.

                 

                Also, total value for Total % free not showing.

                 

                Thanks

                V

                • 5. Re: Storage usage for a particular data store
                  LucD Guru
                  User ModeratorsCommunity WarriorsvExpert

                  You didn't ask for Total % Free.
                  That would be an average, not a total (which doesn't make sense for percentages).

                  Change the line in the Totals select to

                   

                      @{N='FreeSpaceGB%';E={($report | Measure-Object -Property 'FreeSpaceGB%' -Average).Average}},

                   

                  There is an asterisk at the end of those strings.

                  Uncomment the one you want.

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 6. Re: Storage usage for a particular data store
                    vmk2014 Expert

                    just to confirm $report += '' | Select @{N='Name';E={'Total'}},

                     

                    need to replace by  @{N='FreeSpaceGB%';E={($report | Measure-Object -Property 'FreeSpaceGB%' -Average).Average}},

                     

                    but it will give only value for  % average percentage free. I'm looking for  total for Used space/Avaiable space and % Remaining (Average as you said)

                     

                    thanks

                    V

                     

                     

                    • 7. Re: Storage usage for a particular data store
                      LucD Guru
                      Community WarriorsUser ModeratorsvExpert

                      You need to replace this line

                       

                      @{N='FreeSpaceGB%';E={}},

                       

                      with this line

                       

                      @{N='FreeSpaceGB%';E={($report | Measure-Object -Property 'FreeSpaceGB%' -Average).Average}},
                      Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                      • 8. Re: Storage usage for a particular data store
                        vmk2014 Expert

                        My apology, i deleted the thread by mistake. Can you please paste it again. I did mark  as correct but while editing sentence it got deleted.

                        • 9. Re: Storage usage for a particular data store
                          LucD Guru
                          User ModeratorsvExpertCommunity Warriors

                          You mean this latest version?

                           

                          $dsName = 'Windows_PowerMax_*'

                          $report = Get-Datastore -Name $dsName |

                          Select Name,

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

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

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

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

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

                              @{N='TotalVM';E={$_.ExtensionData.Vm.Count}},

                              @{N='VMUsedGB';E={[math]::Round((Get-VM -Datastore $_ | Measure-Object -Property UsedSpaceGB -Sum).Sum)}},

                              @{N='SnapshotGB';E={[math]::Round((Get-vm -Datastore $_ | Get-Snapshot | Measure-Object -Property SizeGB -Sum).Sum)}}


                          $report += '' | Select @{N='Name';E={'Total'}},

                              @{N='CapacityGB';E={($report | Measure-Object -Property CapacityGB -Sum).Sum}},

                              @{N='UsedGB';E={($report | Measure-Object -Property UsedGB -Sum).Sum}},

                              @{N='UsedGB%';E={}},

                              @{N='FreeSpaceGB';E={($report | Measure-Object -Property FreeSpaceGB -Sum).Sum}},

                              @{N='FreeSpaceGB%';E={($report | Measure-Object -Property 'FreeSpaceGB%' -Average).Average}},

                              @{N='TotalVM';E={}},

                              @{N='VMUsedGB';E={}},

                              @{N='SnapshotGB';E={}}


                          $report | Export-Csv -Path D:\temp\StorageUsage2.csv -NoTypeInformation -UseCulture

                          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                          • 10. Re: Storage usage for a particular data store
                            vmk2014 Expert

                            Yes Sir. Thank you Again.