VMware Cloud Community
kkhenson
Contributor
Contributor

How to total DataStoreCluster Capacity and FreeSpace not individual DataStores?

I have seen several examples of generating a report that list the CapacityTB and FreeSpaceTB for a individual Datastores within a DataStoreCluster, but I cannot determine how to just generate:

1.  The total CapacityTB of a data store cluster

2.  The total FreeSpaceTB of a data store cluster

3.  Determine a Provisioned % of a data store cluster, e.g FreeSpaceTB / CapacityTB

I had been using an example that Lucd posted and lightly modified:

foreach ($vc in $VIServer) {

Get-DatastoreCluster -Server $vc |

  Select @{N = 'vCenter'; E = {$vc.Name}},

   @{N = 'Datacenter'; E = {(Get-Datastore -RelatedObject $_ | select -First 1).Datacenter.Name}},

   @{N = 'DSC'; E = {"some DataStoreCluster"}},

  CapacityGB,

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

   @{N = 'Freespace%'; E = {[math]::Round($_.FreespaceTB / $_.CapacityTB * 100, 1)}},

   @{N = 'ProvisionedSpaceTB'; E = {

   [math]::Round(($_.ExtensionData.Summary.Capacity - $_.Extensiondata.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted) / 1TB, 2)}

   },

   @{N = 'UnCommittedTB'; E = {[math]::Round($_.ExtensionData.Summary.Uncommitted / 1TB, 2)}},

   @{N = 'VM'; E = {((Get-View -Id $_.ExtensionData.ChildEntity).VM.Count | Measure-Object -Sum).Sum}}

}

But it only returns individual DataStores, when I what I really want is to see total for the DataStoreCluster.

I would really love to just limit it to the DataStoreClusters within a specific Cluster of the DataCenter.  I'm exhausted my very limited PowerShell skills.

0 Kudos
3 Replies
jatinjsk
Enthusiast
Enthusiast

This has been simplified with Get-DatastoreCluster cmdlet.

Please execute below

Get-DatastoreCluster |Select-object Name, @{N="CapacityTB";E={[math]::Round($_.CapacityGB/1024,2)}}, @{N="FreeSpaceTB";E={[math]::Round($_.FreeSpaceGB/1024,2)}}
Thanks,
Jatin Purohit
0 Kudos
LucD
Leadership
Leadership

Not sure why you would only see datastores being returned, the snippet uses Get-DatastoreCluster.

Fixed a couple of inconsistencies and added the requested properties, this should do the trick.

foreach ($vc in $global:DefaultVIServers)

{

   Get-DatastoreCluster -Server $vc |

   Select-Object @{N = 'vCenter'; E = { $vc.Name } },

   @{N = 'Datacenter'; E = { (Get-Datastore -RelatedObject $_ | Select-Object -First 1).Datacenter.Name } },

   @{N = 'DSC'; E = { "some DataStoreCluster" } },

   @{N = 'CapacityTB'; E = { $_.CapacityGB / 1KB } },

   @{N = 'FreespaceTB'; E = { [math]::Round($_.FreespaceGB / 1KB, 2) } },

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

   @{N = 'ProvisionedSpaceTB'; E = {

   [math]::Round(($_.ExtensionData.Summary.Capacity - $_.Extensiondata.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted) / 1TB, 2) }

   },

   @{N = 'ProvisionedSpace%'; E = {

   [math]::Round((($_.ExtensionData.Summary.Capacity - $_.Extensiondata.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted) / 1GB) / $_.CapacityGB * 100, 1) }

   },

   @{N = 'UnCommittedTB'; E = { [math]::Round($_.ExtensionData.Summary.Uncommitted / 1TB, 2) } },

   @{N = 'VM'; E = { ((Get-View -Id $_.ExtensionData.ChildEntity).VM.Count | Measure-Object -Sum).Sum } }

}


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

0 Kudos
kkhenson
Contributor
Contributor

This does give me what I need without the additional expression to calculate the % already provisioned, which LucD answer does include.  I'm using a combination of both answers, and I really appreciate the responses from both of you. 

0 Kudos