3 Replies Latest reply on Sep 23, 2020 12:41 AM by LucD

    Total Storage Available for Cluster

    vmk2014 Expert

      Hi All,

       

      I'm trying to retrieve the Total storage available for all Cluster available in the vCenter. Below script retrieve only for one cluster i.e. Cluster1.

      I need help to retrieve the Total Storage and available storage value for all the cluster instead of one specific "Cluster 1" value. is it possible to retrieve for all the Cluster in vCenter from Power Cli ?

       

      Import-Module VMware.VimAutomation.Core

      Connect-VIServer -Server 10.1x.y.z -user "mydomain\username"

       

      $date = Get-Date

       

      $datastore = Get-Cluster -Name Cluster1 | Get-Datastore | Where-Object {$_.Type -eq 'VMFS' -and $_.Extensiondata.Summary.MultipleHostAccess}

       

      $TotalStorage = ($datastore | Measure-Object -Property CapacityMB -Sum).Sum / 1024

      $AvailableStorage = ($datastore | Measure-Object -Property FreeSpaceMB -Sum).Sum / 1024

       

      $endpoint = "https://api.powerbi.com/beta/83fe1fa2-fa52-4376-b7f0-cb645a5fcfced/datasets/d57970bc-60b3-46e6-b23b-d782431a72be/rows?key=2zEhgN9mu%2BEH%2FI2Cbk9hd2Kw4b5c84YaO6W8gzFcZbBnO6rti3N631Gjw%2FveNXSBxwR84VcWPGOSrheNwQnCbw%3D%3D"

      $payload = @{

      "Date" = $Date

      "Total Storage" = $TotalStorage

      "Available Storage" = $AvailableStorage

      }

      Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))

       

      Disconnect-VIServer * -Confirm:$false

        • 1. Re: Total Storage Available for Cluster
          LucD Guru
          User ModeratorsvExpertCommunity Warriors

          You could do something like this

           

          Import-Module VMware.VimAutomation.Core

          Connect-VIServer -Server 10.1x.y.z -user "mydomain\username"


          $date = Get-Date

          $endpoint = "https://api.powerbi.com/beta/83fe1fa2-fa52-4376-b7f0-cb645a5fcfced/datasets/d57970bc-60b3-46e6-b23b-d782431a72be/rows?key=2zEhgN9mu%2BEH%2FI2Cbk9hd2Kw4b5c84YaO6W8gzFcZbBnO6rti3N631Gjw%2FveNXSBxwR84VcWPGOSrheNwQnCbw%3D%3D"


          Get-Cluster -PipelineVariable cluster |

          ForEach-Object -Process {

              $datastore = Get-Datastore -RelatedObject $cluster |

                  Where-Object {$_.Type -eq 'VMFS' -and $_.Extensiondata.Summary.MultipleHostAccess}

              $TotalStorage = ($datastore | Measure-Object -Property CapacityMB -Sum).Sum / 1024

              $AvailableStorage = ($datastore | Measure-Object -Property FreeSpaceMB -Sum).Sum / 1024

              $payload = @{

                  "Date" = $Date

                  "Cluster" = $cluster.Name

                  "Total Storage" = $TotalStorage

                  "Available Storage" = $AvailableStorage

              }

              Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))

          }


          Disconnect-VIServer * -Confirm:$false

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Total Storage Available for Cluster
            vmk2014 Expert

            First of all thank you for your help. I did try to excute the script but it fails with an error. Anything i'm missing ?

             

            PS D:\xyz> D:\xyz\Get-FreeSpace-BI.ps1

             

             

            Name                           Port  User                         

            ----                           ----  ----                         

            mydomain... 443   mydomain\username            

            Get-Datastore : 9/23/2020 2:31:23 AM Get-Datastore The Location parameter accepts only Datacenter, Folder  and

            DatastoreCluster objects. You specified 'ClusterImpl'.

            At D:\xyz\Get-FreeSpace-BI.ps1:14 char:18

            +     $datastore = Get-Datastore -Location $cluster |

            +                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                + CategoryInfo          : InvalidArgument: (:) [Get-Datastore], InvalidArgument

                + FullyQualifiedErrorId : Core_GetDatastore_TryValidateParameterListEx_OnProcessRecord_LocationUnsupportedType,V

               Mware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastore

             

             

             

            Get-Datastore : 9/23/2020 2:31:24 AM Get-Datastore The Location parameter accepts only Datacenter, Folder  and

            DatastoreCluster objects. You specified 'ClusterImpl'.

            At D:\XYZ\Get-FreeSpace-BI.ps1:14 char:18

            +     $datastore = Get-Datastore -Location $cluster |

            +                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                + CategoryInfo          : InvalidArgument: (:) [Get-Datastore], InvalidArgument

                + FullyQualifiedErrorId : Core_GetDatastore_TryValidateParameterListEx_OnProcessRecord_LocationUnsupportedType,V

               Mware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastore

             

             

             

            Get-Datastore : 9/23/2020 2:31:24 AM Get-Datastore The Location parameter accepts only Datacenter, Folder  and

            DatastoreCluster objects. You specified 'ClusterImpl'.

            At D:\XYZ\Get-FreeSpace-BI.ps1:14 char:18

            +     $datastore = Get-Datastore -Location $cluster |

            +                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                + CategoryInfo          : InvalidArgument: (:) [Get-Datastore], InvalidArgument

                + FullyQualifiedErrorId : Core_GetDatastore_TryValidateParameterListEx_OnProcessRecord_LocationUnsupportedType,V

               Mware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastore

             

             

             

            Get-Datastore : 9/23/2020 2:31:24 AM Get-Datastore The Location parameter accepts only Datacenter, Folder  and

            DatastoreCluster objects. You specified 'ClusterImpl'.

            At D:\XYZ\Get-FreeSpace-BI.ps1:14 char:18

            +     $datastore = Get-Datastore -Location $cluster |

            +                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                + CategoryInfo          : InvalidArgument: (:) [Get-Datastore], InvalidArgument

                + FullyQualifiedErrorId : Core_GetDatastore_TryValidateParameterListEx_OnProcessRecord_LocationUnsupportedType,V

               Mware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastore

             

             

             

            Get-Datastore : 9/23/2020 2:31:24 AM Get-Datastore The Location parameter accepts only Datacenter, Folder  and

            DatastoreCluster objects. You specified 'ClusterImpl'.

            At D:\XYZ\Get-FreeSpace-BI.ps1:14 char:18

            +     $datastore = Get-Datastore -Location $cluster |

            +                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                + CategoryInfo          : InvalidArgument: (:) [Get-Datastore], InvalidArgument

                + FullyQualifiedErrorId : Core_GetDatastore_TryValidateParameterListEx_OnProcessRecord_LocationUnsupportedType,V

               Mware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastore

             

             

             

            Get-Datastore : 9/23/2020 2:31:25 AM Get-Datastore The Location parameter accepts only Datacenter, Folder  and

            DatastoreCluster objects. You specified 'ClusterImpl'.

            At D:\XYZ\Get-FreeSpace-BI.ps1:14 char:18

            +     $datastore = Get-Datastore -Location $cluster |

            +                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                + CategoryInfo          : InvalidArgument: (:) [Get-Datastore], InvalidArgument

                + FullyQualifiedErrorId : Core_GetDatastore_TryValidateParameterListEx_OnProcessRecord_LocationUnsupportedType,V

               Mware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastore

             

             

             

            Get-Datastore : 9/23/2020 2:31:25 AM Get-Datastore The Location parameter accepts only Datacenter, Folder  and

            DatastoreCluster objects. You specified 'ClusterImpl'.

            At D:\XYZ\Get-FreeSpace-BI.ps1:14 char:18

            +     $datastore = Get-Datastore -Location $cluster |

            +                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                + CategoryInfo          : InvalidArgument: (:) [Get-Datastore], InvalidArgument

                + FullyQualifiedErrorId : Core_GetDatastore_TryValidateParameterListEx_OnProcessRecord_LocationUnsupportedType,V

               Mware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastore

             

             

             

            Get-Datastore : 9/23/2020 2:31:25 AM Get-Datastore The Location parameter accepts only Datacenter, Folder  and

            DatastoreCluster objects. You specified 'ClusterImpl'.

            At D:\XYZ\Get-FreeSpace-BI.ps1:14 char:18

            +     $datastore = Get-Datastore -Location $cluster |

            +                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                + CategoryInfo          : InvalidArgument: (:) [Get-Datastore], InvalidArgument

                + FullyQualifiedErrorId : Core_GetDatastore_TryValidateParameterListEx_OnProcessRecord_LocationUnsupportedType,V

               Mware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastore

             

             

             

            Get-Datastore : 9/23/2020 2:31:25 AM Get-Datastore The Location parameter accepts only Datacenter, Folder  and

            DatastoreCluster objects. You specified 'ClusterImpl'.

            At D:\XYZ\Get-FreeSpace-BI.ps1:14 char:18

            +     $datastore = Get-Datastore -Location $cluster |

            +                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                + CategoryInfo          : InvalidArgument: (:) [Get-Datastore], InvalidArgument

                + FullyQualifiedErrorId : Core_GetDatastore_TryValidateParameterListEx_OnProcessRecord_LocationUnsupportedType,V

               Mware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastore

             

             

            Thanks

            V

            • 3. Re: Total Storage Available for Cluster
              LucD Guru
              Community WarriorsvExpertUser Moderators

              My bad, that should have been RelatedObject instead of Location.
              The code above is corrected

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz