JPSVM
Contributor
Contributor

Datastore capacity available per cluster

Jump to solution

Hi guys

Just wondering anyone can help me ? Looking for a script which counts datastore free space (only VMFS not Local) and how many VMs can be provisioned per cluster taking the average size of a VM as 50GB.

Found various scripts , but nothing showing the total VMs can be provisioned based on available free space.

Thanks in advance

0 Kudos
1 Solution

Accepted Solutions
Madmax01
Expert
Expert

Hi,

could you test out. that should do you're request based on

Total = 1000GB

free = 500GB

10% = 100GB

(500GB - 100GB)/50 = 8

Connect-VIServer -server "server name " -credential (get-credential)

$report = @()

$clusterDSReport = @()

foreach($cluster in Get-Cluster){

    $dsClusterFree = 0

  $dsClusterCapacity = 0

    Get-Datastore -RelatedObject $cluster | where {$_.type -match "VMFS" -and $_.Name -notmatch "local|snap"} | %{

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

        $info.Datacenter = $_.Datacenter

        $info.Cluster = $cluster.Name

        $info.Name = $_.Name

        $info.Capacity = [math]::Round($_.capacityGB,2)

        $info.Available = [math]::Round($_.FreeSpaceGB,2)

        $report += $info

        $dsClusterCapacity += $info.Capacity

  $dsClusterFree += $info.Available

    }

    $clusterInfo = "" |Select Cluster, "Available Slots"

    #$clusterInfo = 'Cluster','Available slots'

    $clusterInfo.Cluster = $cluster.Name

    $clusterInfo.'Available slots' = [math]::Round($dsClusterFree - ($dsClusterCapacity * 0.1))/50

    $clusterDSReport += $clusterInfo

}

$report | Export-Csv "C:\vmware\scripts\datastore\cluster-ds.csv" -NoTypeInformation -UseCulture

$clusterDSReport | Export-Csv "C:\vmware\scripts\datastore\cluster-free-VM-slots.csv" -NoTypeInformation -UseCulture




View solution in original post

0 Kudos
10 Replies
LucD
Leadership
Leadership

Isn't that just summarising the free space from all VMFS datastores in the cluster, and then dividing by 50 ?

Which script have you been looking at ?


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

0 Kudos
JPSVM
Contributor
Contributor

Thats correct. Add up free spaces from all VMFS datastores ( not local storage) for each cluster separately and deduct 10 % reserve capacity divided by 50.

Total Free Space Available in a cluster - 10 % of Total space available ( Reserve Capacity)  / 50

Hope it makes sense.

Thanks a lot

0 Kudos
LucD
Leadership
Leadership

And which script are you using for the free space ?

So I can check how I can add the number of slots available


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

0 Kudos
JPSVM
Contributor
Contributor

Hi Lucd

Apologies for the late reply. Please find the below script.

Connect-VIServer -server "server name " -credential (get-credential)

$report = @()

foreach($cluster in Get-Cluster){

get-cluster $cluster | Get-VMHost | get-datastore | where {$_.Name -notmatch "local|snap"} | %{

    #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:\vmware\scripts\datastore\cluster-ds.csv" -NoTypeInformation -UseCulture

0 Kudos
LucD
Leadership
Leadership

Try something like this.

It will produce a 2nd SVC with the Cluster-Free slots info

Connect-VIServer -server "server name " -credential (get-credential)

$report = @()

$clusterDSReport = @()

foreach($cluster in Get-Cluster){

    $dsClusterFree = 0

    Get-Datastore -RelatedObject $cluster | where {$_.Name -notmatch "local|snap"} | %{

        $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

        $dsClusterFree += $_.ExtensionData.Summary.FreeSpace/1GB

    }

    $clusterInfo = 'Cluster','Available slots'

    $clusterInfo.Cluster = $cluster.Name

    $clusterInfo.'Available slots' = [math]::Floor(($dsClusterFree * 0.9)/50)

    $clusterDSReport += $clusterInfo

}

$report | Export-Csv "C:\vmware\scripts\datastore\cluster-ds.csv" -NoTypeInformation -UseCulture

$clusterDSReport | Export-Csv "C:\vmware\scripts\datastore\cluster-free-VM-slots.csv" -NoTypeInformation -UseCulture


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

JPSVM
Contributor
Contributor

Hi Lucd

Not sure where it is adding the total free space of each lun in the cluster and deducting the reserve capacity.

However , it is throwing the below error.

Property 'Cluster' cannot be found on this object; make sure it exists and is

settable.

At C:\vmware\scripts\datastore\DSMaths.ps1:41 char:5

+     $clusterInfo.Cluster = $cluster.Name

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

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : PropertyAssignmentException

Property 'Available slots' cannot be found on this object; make sure it exists

and is settable.

At C:\vmware\scripts\datastore\DSMaths.ps1:43 char:5

+     $clusterInfo.'Available slots' = [math]::Floor(($dsClusterFree * 0.9)/50)

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

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : PropertyAssignmentException

Many Thanks

0 Kudos
Madmax01
Expert
Expert

@LucD: Hope is ok Smiley Wink

i changed it slightly:

i changed:

- Extended Datastore Query to Type VMFS

- Did a Select for Clusters and Available Slots because of the Error.

that working on my Side

@jpsvm: you having unique Datastore labelings?  as it's trying to find Names not matching "local", snap"

Connect-VIServer -server "server name " -credential (get-credential)

$report = @()

$clusterDSReport = @()

$report = @()

$clusterDSReport = @()

foreach($cluster in Get-Cluster){

    $dsClusterFree = 0

    Get-Datastore -RelatedObject $cluster | where {$_.type -match "VMFS" -and $_.Name -notmatch "local|snap"| %{

        $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

        $dsClusterFree += $_.ExtensionData.Summary.FreeSpace/1GB

    }

    $clusterInfo = "" |Select Cluster, "Available Slots"

    $clusterInfo.Cluster = $cluster.Name

    $clusterInfo.'Available slots' = [math]::Floor(($dsClusterFree * 0.9)/50)

    $clusterDSReport += $clusterInfo

}

$report | Export-Csv "C:\vmware\scripts\datastore\cluster-ds.csv" -NoTypeInformation -UseCulture

$clusterDSReport | Export-Csv "C:\vmware\scripts\datastore\cluster-free-VM-slots.csv" -NoTypeInformation -UseCulture




JPSVM
Contributor
Contributor

It worked like a charm.. Thanks to you both.

@ :  wants to exclude local storage when calculating the free space.

Just one amendment needed please

The reserve capacity should be the 10 % of total capacity of each lun. Is there any way to fit this please?

So the final result should  be  like this :

Total free space in the cluster  minus  10 % of TOTAL CAPACITY of each lun divided by 50

At the moment , it is just calculating the 10% of free space as reserve capacity

Thanks Once again

Cheers

0 Kudos
Madmax01
Expert
Expert

Hi,

could you test out. that should do you're request based on

Total = 1000GB

free = 500GB

10% = 100GB

(500GB - 100GB)/50 = 8

Connect-VIServer -server "server name " -credential (get-credential)

$report = @()

$clusterDSReport = @()

foreach($cluster in Get-Cluster){

    $dsClusterFree = 0

  $dsClusterCapacity = 0

    Get-Datastore -RelatedObject $cluster | where {$_.type -match "VMFS" -and $_.Name -notmatch "local|snap"} | %{

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

        $info.Datacenter = $_.Datacenter

        $info.Cluster = $cluster.Name

        $info.Name = $_.Name

        $info.Capacity = [math]::Round($_.capacityGB,2)

        $info.Available = [math]::Round($_.FreeSpaceGB,2)

        $report += $info

        $dsClusterCapacity += $info.Capacity

  $dsClusterFree += $info.Available

    }

    $clusterInfo = "" |Select Cluster, "Available Slots"

    #$clusterInfo = 'Cluster','Available slots'

    $clusterInfo.Cluster = $cluster.Name

    $clusterInfo.'Available slots' = [math]::Round($dsClusterFree - ($dsClusterCapacity * 0.1))/50

    $clusterDSReport += $clusterInfo

}

$report | Export-Csv "C:\vmware\scripts\datastore\cluster-ds.csv" -NoTypeInformation -UseCulture

$clusterDSReport | Export-Csv "C:\vmware\scripts\datastore\cluster-free-VM-slots.csv" -NoTypeInformation -UseCulture




View solution in original post

0 Kudos
JPSVM
Contributor
Contributor

Thanks a lot.. Its working great..

Converted to a html output, all good

Cheers

0 Kudos