1 2 Previous Next 26 Replies Latest reply on May 10, 2016 10:35 AM by baburaju

    PowerCli DataStore Audit?

    Ribcap Novice

      Hello,

       

      I was wondering if someone could help me with a script.  I need to do an audit of our datastores with capacity, provisioned, and available.  I did find a snippet of code which returns the information I need, but is there a way to indicate which cluster these DataStores are assigned to?

       

      Here is the code I'm using.

       

       

      $report
      = @() get-datastore
      
      | % { 
      $info = "" | select DataCenter, Name, Capacity, Provisioned, Available 
      $info.Datacenter = $_.Datacenter 
      $info.Name = $_.Name 
      $info.Capacity = [math]::Round($_.capacityMB/1024,2) 
      $info.Provisioned = [math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2) 
      $info.Available = [math]::Round($info.Capacity - $info.Provisioned,2) 
      $report += $info }
      #$report | sort Available | format-table –auto
      
      
      
      
      
      
      
      
      
      

       

      Ideally I'd like to have a spreadsheet with a seperate worksheet for each Cluster, but having a single sheet with all datastores and their cluster would be fine as well.

       

      Thx

        • 1. Re: PowerCli DataStore Audit?
          LucD Guru
          vExpertUser ModeratorsCommunity Warriors

          Try something like this

           

          $report = @()
          
          foreach($cluster in Get-Cluster){
              Get-VMHost -Location $cluster | Get-Datastore | %{
                  $info = "" | select DataCenter, Cluster, Name, Capacity, Provisioned, Available 
                  $info.Datacenter = $_.Datacenter
                  $info.Cluster = $cluster.Name
                  $info.Name = $_.Name 
                  $info.Capacity = [math]::Round($_.capacityMB/1024,2) 
                  $info.Provisioned = [math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2) 
                  $info.Available = [math]::Round($info.Capacity - $info.Provisioned,2) 
                  $report += $info
              } }
          $report | Export-Csv "C:\cluster-ds.csv" -NoTypeInformation -UseCulture

           

          If you want to have a cluster per worksheet in a spreadsheet, you could use the function from my post called Beyond Export-Csv: Export-Xls

          The script would change slightly.

           

           foreach($cluster in Get-Cluster){
              $report = @()
              Get-VMHost -Location $cluster | Get-Datastore | %{
                  $info = "" | select DataCenter, Cluster, Name, Capacity, Provisioned, Available 
                  $info.Datacenter = $_.Datacenter
                  $info.Cluster = $cluster.Name
                  $info.Name = $_.Name 
                  $info.Capacity = [math]::Round($_.capacityMB/1024,2) 
                  $info.Provisioned = [math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2) 
                  $info.Available = [math]::Round($info.Capacity - $info.Provisioned,2) 
                  $report += $info
              }    
          $report | Export-Xls -Path C:\ds-cluster.xls -WorksheetName $cluster.Name -SheetPosition "end"
          }
          • 2. Re: PowerCli DataStore Audit?
            Ribcap Novice

            Thank you soo much!  Both work flawlessly.

             

            I do have a few more questions, but the reports were needed and I can now provide them.  The other items I'm going to try to figure out on my own...hopefully I can better undertand things this way  .

             

            Anyways, thanks again....not only for this response, but for all the information that you've given me indirectly.

            • 3. Re: PowerCli DataStore Audit?
              ayanes Novice

              Hi Luc,

              I am using this script together with your xls function and it works great.

              Is it possible since I am using vsphere 5 with clustered datastores to get the total amount of presented storage in the cluster, total amount of provisioned storage, total amount of used storage per TAB.

              Do a formula of presented storage in the cluster minus total amount of provisioned storage. I wanna use this to do storage planning since I am using thin provisioning.

               

              Thanks,

              Alberto-

              • 4. Re: PowerCli DataStore Audit?
                LucD Guru
                User ModeratorsCommunity WarriorsvExpert

                A datastorecluster is created on the datacenter level.

                Are your DSC dedicated to specific clusters, or can a DSC be used from multiple cluster in your environment ?

                • 5. Re: PowerCli DataStore Audit?
                  ayanes Novice

                  Each DSC is used by one cluster. Not shared by multiple clusters.

                   

                  thanks,

                  Alberto

                  • 6. Re: PowerCli DataStore Audit?
                    ayanes Novice

                    I meant in my environment.

                    • 7. Re: PowerCli DataStore Audit?
                      JT1024 Novice

                      I added FreeSpaceMB.  With deduped data, 'available' can show negative values and doesn't always give a good picture to what is really free.

                       

                      $report = @()

                       

                       

                      foreach($cluster in Get-Cluster){

                          Get-VMHost -Location $cluster | Get-Datastore | %{

                              $info = "" | select DataCenter, Cluster, Name, Capacity, FreeSpaceMB, Provisioned, Available

                              $info.Datacenter = $_.Datacenter

                              $info.Cluster = $cluster.Name

                              $info.Name = $_.Name

                              $info.Capacity = [math]::Round($_.capacityMB/1024,2)

                              $info.FreeSpaceMB = $_.ExtensionData.Summary.FreeSpace/1GB

                              $info.Provisioned = [math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2)

                              $info.Available = [math]::Round($info.Capacity - $info.Provisioned,2)

                              $report += $info

                          }

                      }

                      • 8. Re: PowerCli DataStore Audit?
                        russjar Enthusiast

                        Hi

                         

                        How do we add VMs on the Datastore to this report?

                         

                        Cheers

                        • 9. Re: PowerCli DataStore Audit?
                          LucD Guru
                          User ModeratorsCommunity WarriorsvExpert

                          Try something like this

                           

                          $report = @()

                           

                          foreach($cluster in Get-Cluster){

                              foreach($esx in Get-VMHost -Location $cluster){

                                  foreach($vm in Get-VM -Location $esx){

                                      Get-Datastore -RelatedObject $vm | %{

                                          $info = "" | select DataCenter, Cluster, VM, Datastore, Capacity, FreeSpaceMB, Provisioned, Available

                                          $info.Datacenter = $_.Datacenter

                                          $info.Cluster = $cluster.Name

                                          $info.VM = $vm.Name

                                          $info.Datastore = $_.Name

                                          $info.Capacity = [math]::Round($_.capacityMB/1024,2)

                                          $info.FreeSpaceMB = $_.ExtensionData.Summary.FreeSpace/1GB

                                          $info.Provisioned = [math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2)

                                          $info.Available = [math]::Round($info.Capacity - $info.Provisioned,2)

                                          $report += $info

                                      }

                                  }

                              }

                          }

                           

                          $report

                           

                          • 10. Re: PowerCli DataStore Audit?
                            russjar Enthusiast

                            Champion thank you.

                            • 11. Re: PowerCli DataStore Audit?
                              scottcardinal Novice

                              hi all i'm looking for a script that i can run against a virtual center to see all changes there were made in the last 24 hours on all luns and vms and who made them. new vm's, added memory, or anything that would take up space on a lun that would be a manual change.

                               

                               

                              thank you in advance!

                              • 12. Re: PowerCli DataStore Audit?
                                raj8 Novice

                                Hi Lucd,

                                 

                                could you please provide me the script in getting datastore report in below format

                                 

                                 

                                     

                                NameCapacity GBProvisioned GB  Capacity in %(provisined/capacity) In Use GBFree GBFree %
                                datastore11290.949218750.740.9492187512899


                                • 13. Re: PowerCli DataStore Audit?
                                  icrow1978 Novice

                                  Hi LucD,

                                   

                                  If possible with that script :

                                   

                                   

                                  $report = @()  foreach($cluster in Get-Cluster){     Get-VMHost -Location $cluster | Get-Datastore | %{         $info = "" | select DataCenter, Cluster, Name, Capacity, Provisioned, Available         $info.Datacenter = $_.Datacenter         $info.Cluster = $cluster.Name         $info.Name = $_.Name         $info.Capacity = [math]::Round($_.capacityMB/1024,2)         $info.Provisioned = [math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2)         $info.Available = [math]::Round($info.Capacity - $info.Provisioned,2)         $report += $info
                                      } } 
                                  $report | Export-Csv "C:\cluster-ds.csv" -NoTypeInformation -UseCulture



                                  Get a report for 2 cluster? or in case that is not possible, get a report for an specfic  cluster e.g Cluster-test .

                                  I test the script and work fine but if a have 2 cluster the script take either cluster-test or cluster-test1.

                                   

                                  Best regards

                                  • 14. Re: PowerCli DataStore Audit?
                                    LucD Guru
                                    vExpertCommunity WarriorsUser Moderators

                                    You can specify one or more clusternames on the Get-CLuster cmdlet.

                                    The outer loop could be

                                     

                                    foreach($cluster in Get-Cluster -Name cluster-test,cluster-test1)

                                     

                                     

                                    1 2 Previous Next