VMware Cloud Community
vmk2014
Expert
Expert
Jump to solution

Total Storage Available for Cluster

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-..."

$payload = @{

"Date" = $Date

"Total Storage" = $TotalStorage

"Available Storage" = $AvailableStorage

}

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

Disconnect-VIServer * -Confirm:$false

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

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-..."


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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
vmk2014
Expert
Expert
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos