Automation

 View Only
Expand all | Collapse all

Datastore capacity available per cluster

  • 1.  Datastore capacity available per cluster

    Posted May 27, 2016 11:25 AM

    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



  • 2.  RE: Datastore capacity available per cluster

    Posted May 27, 2016 01:26 PM

    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 ?



  • 3.  RE: Datastore capacity available per cluster

    Posted May 27, 2016 02:04 PM

    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



  • 4.  RE: Datastore capacity available per cluster

    Posted May 27, 2016 05:00 PM

    And which script are you using for the free space ?

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



  • 5.  RE: Datastore capacity available per cluster

    Posted May 31, 2016 08:07 AM

    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



  • 6.  RE: Datastore capacity available per cluster

    Posted May 31, 2016 04:15 PM

    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



  • 7.  RE: Datastore capacity available per cluster

    Posted Jun 01, 2016 08:38 AM

    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



  • 8.  RE: Datastore capacity available per cluster

    Posted Jun 01, 2016 11:46 AM

    @LucD: Hope is ok :smileywink:

    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






  • 9.  RE: Datastore capacity available per cluster

    Posted Jun 01, 2016 02:46 PM

    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



  • 10.  RE: Datastore capacity available per cluster
    Best Answer

    Posted Jun 01, 2016 04:39 PM

    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






  • 11.  RE: Datastore capacity available per cluster

    Posted Jun 02, 2016 03:46 PM

    Thanks a lot.. Its working great..

    Converted to a html output, all good

    Cheers