Automation

 View Only
  • 1.  Total Storage Available for Cluster

    Posted Sep 23, 2020 05:58 AM

    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



  • 2.  RE: Total Storage Available for Cluster

    Posted Sep 23, 2020 07:15 AM

    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



  • 3.  RE: Total Storage Available for Cluster

    Posted Sep 23, 2020 07:39 AM

    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



  • 4.  RE: Total Storage Available for Cluster
    Best Answer

    Posted Sep 23, 2020 07:42 AM

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