Automation

 View Only
  • 1.  Datastore details with cluster name.

    Posted Aug 06, 2020 01:43 PM

    Hi

    I have written the below script, but don't how to add and get the cluster name with respective to the datastore, also need to add sum of UsableFreeSpace in cluster wise.

    Any help would be appreciable please.

    $report = @()

    Connect-VIServer -Server VCServer

    $date = Get-Date -Format 'yyyyMMdd'

    $datastores = Get-Datastore | where {$_.Type -eq "VMFS"}

    foreach($store in $datastores){

    $storeinfo = "" | Select DatastoreName, CapacityGB, FreeSpaceGB, FreeSpaceInPercent, UsableFreeSpace

    $datastoreview = get-datastore -Name $store.Name | Get-View | select -ExpandProperty summary

    $CapacityGB = [math]::round($datastoreview.Capacity/1GB,2)

    $FreeSpaceGB = [math]::round($datastoreview.FreeSpace/1GB,2)

    $Percent = [math]::round(($datastoreview.FreeSpace/$datastoreview.Capacity) * 100)

    $Usable = [math]::round((($datastoreview.FreeSpace) - ($datastoreview.Capacity/2))/1GB,2)

    $storeinfo.DatastoreName = $store.Name

    $storeinfo.CapacityGB = $CapacityGB

    $storeinfo.FreeSpaceGB = $FreeSpaceGB

    $storeinfo.FreeSpaceInPercent = $Percent

    $storeinfo.UsableFreeSpace = if($Percent -ge 55) { $Usable } else { 'Not enough space'}

    $report += $storeinfo

    }

    $report | Export-CSV -Path "D:\Datastore_Report_$date.csv" -NoTypeInformation -UseCulture

    Disconnect-VIServer -Server VCServer -Confirm:$false

    Thanks in advance,



  • 2.  RE: Datastore details with cluster name.

    Posted Aug 06, 2020 04:57 PM
    $report = @()


    Connect-VIServer -Server VCServer


    $date = Get-Date -Format 'yyyyMMdd'


    $DsClusters = Get-DatastoreCluster


    foreach ($DSCluster in $DsClusters){

        $datastores = Get-Datastore | where {$_.Type -eq "VMFS"}


        foreach($store in $datastores){

            $storeinfo = "" | Select DatastoreName, CapacityGB, FreeSpaceGB, FreeSpaceInPercent, UsableFreeSpace

            $datastoreview = get-datastore -Name $store.Name | Get-View | select -ExpandProperty summary

            $CapacityGB = [math]::round($datastoreview.Capacity/1GB,2)

            $FreeSpaceGB = [math]::round($datastoreview.FreeSpace/1GB,2)

            $Percent = [math]::round(($datastoreview.FreeSpace/$datastoreview.Capacity) * 100)

            $Usable = [math]::round((($datastoreview.FreeSpace) - ($datastoreview.Capacity/2))/1GB,2)


            $storeinfo.DatastoreName = $store.Name

            $storeinfo.DatastoreClusterName = $DSCluster.Name

            $storeinfo.CapacityGB = $CapacityGB

            $storeinfo.FreeSpaceGB = $FreeSpaceGB

            $storeinfo.FreeSpaceInPercent = $Percent

            $storeinfo.UsableFreeSpace = if($Percent -ge 55) { $Usable } else { 'Not enough space'}

           

            #Not sure where in the report you'd want this.

            $totalUseableFreeSpace += $Usable

           

            $report += $storeinfo


        }

    }

    $report | Export-CSV -Path "D:\Datastore_Report_$date.csv" -NoTypeInformation -UseCulture

    Disconnect-VIServer -Server VCServer -Confirm:$false



  • 3.  RE: Datastore details with cluster name.

    Posted Aug 06, 2020 07:14 PM

    Its not getting appropriate cluster name with respective to the datastores.

    $totalUseableFreeSpace is like adding all usable freespace in clusterwise and providing sum value.



  • 4.  RE: Datastore details with cluster name.

    Posted Aug 06, 2020 08:41 PM

    DOH - Still not sure where in the report you want the cluster free space.  updated below:

    $report = @()

    Connect-VIServer -Server VCServer

    $date = Get-Date -Format 'yyyyMMdd'

    $DsClusters = Get-DatastoreCluster

    foreach ($DSCluster in $DsClusters){

        $dsclusterName = $DSCluster.Name

        $datastores = Get-DatastoreCluster $dsclusterName | Get-Datastore | where {$_.Type -eq "VMFS"}

        $ClusterFreeSpace = 0


        foreach($store in $datastores){

            $storeinfo = "" | Select DatastoreName, CapacityGB, FreeSpaceGB, FreeSpaceInPercent, UsableFreeSpace

            $datastoreview = get-datastore -Name $store.Name | Get-View | select -ExpandProperty summary

            $CapacityGB = [math]::round($datastoreview.Capacity/1GB,2)

            $FreeSpaceGB = [math]::round($datastoreview.FreeSpace/1GB,2)

            $Percent = [math]::round(($datastoreview.FreeSpace/$datastoreview.Capacity) * 100)


            $Usable = [math]::round((($datastoreview.FreeSpace) - ($datastoreview.Capacity/2))/1GB,2)

            $storeinfo.DatastoreName = $store.Name

            $storeinfo.DatastoreClusterName = $DSCluster.Name

            $storeinfo.CapacityGB = $CapacityGB

            $storeinfo.FreeSpaceGB = $FreeSpaceGB

            $storeinfo.FreeSpaceInPercent = $Percent

            $storeinfo.UsableFreeSpace = if($Percent -ge 55) { $Usable } else { 'Not enough space'}


            #Not sure where in the report you'd want this.

            $ClusterFreeSpace += $Usable


            $report += $storeinfo


        }


    }


    $report | Export-CSV -Path "D:\Datastore_Report_$date.csv" -NoTypeInformation -UseCulture


    Disconnect-VIServer -Server VCServer -Confirm:$false



  • 5.  RE: Datastore details with cluster name.

    Posted Aug 07, 2020 11:25 AM

    Hi,

    Super, Thanks a lot ... Now its getting appropriate cluster with respective to datastores name. Can you help me with bit more please.

    for $totalusable space some thing I want to get report like below

           

    DatastoreClusterDatastore NameCapacityGBFreespaceGBFreeSpaceInPercentUsableFreeSpace (>50%)TotalUsableFreeSpace
    DatastoreCluster_ADatastoreA_012000.001500.0075500.001500.00
    DatastoreA_022000.001500.0075500.00
    DatastoreA_032000.001500.0075500.00
    DatastoreA_042000.001000.0050Not enough space
    DatastoreA_052000.001000.0050Not enough space
    DatastoreCluster_BDatastoreB_012000.001000.0050Not enough space1500.00
    DatastoreB_022000.001000.0050Not enough space
    DatastoreB_032000.001500.0075500.00
    DatastoreB_042000.001500.0075500.00
    DatastoreB_052000.001500.0075500.00


  • 6.  RE: Datastore details with cluster name.

    Posted Aug 07, 2020 04:06 PM
    The problem is that the data is not symetrical.


    You are calculating the total cluster available freespace which is technically not part of a single datastore. so the total available space would end up on each line.


    $report = @()


    Connect-VIServer -Server VCServer

    $date = Get-Date -Format 'yyyyMMdd'

    $DsClusters = Get-DatastoreCluster


    foreach ($DSCluster in $DsClusters){

        $dsclusterName = $DSCluster.Name

        $ClusterFreeSpace = $DSCluster.FreeSpaceGB


        $datastores = Get-DatastoreCluster $dsclusterName | Get-Datastore | where {$_.Type -eq "VMFS"}


        foreach($store in $datastores){

            $storeinfo = "" | Select DatastoreName, CapacityGB, FreeSpaceGB, FreeSpaceInPercent, UsableFreeSpace

            $datastoreview = get-datastore -Name $store.Name | Get-View | select -ExpandProperty summary

            $CapacityGB = [math]::round($datastoreview.Capacity/1GB,2)

            $FreeSpaceGB = [math]::round($datastoreview.FreeSpace/1GB,2)

            $Percent = [math]::round(($datastoreview.FreeSpace/$datastoreview.Capacity) * 100)

            $Usable = [math]::round((($datastoreview.FreeSpace) - ($datastoreview.Capacity/2))/1GB,2)

           

            $storeinfo.DatastoreName = $store.Name

            $storeinfo.DatastoreClusterName = $DSCluster.Name

            $storeinfo.CapacityGB = $CapacityGB

            $storeinfo.FreeSpaceGB = $FreeSpaceGB

            $storeinfo.FreeSpaceInPercent = $Percent

            $storeinfo.UsableFreeSpace = if($Percent -ge 55) { $Usable } else { 'Not enough space'}

            # Added this

            $storeinfo.ClusterFreeSpace = $ClusterFreeSpace


            $report += $storeinfo

        }

    }


    $report | Export-CSV -Path "D:\Datastore_Report_$date.csv" -NoTypeInformation -UseCulture


    Disconnect-VIServer -Server VCServer -Confirm:$false



  • 7.  RE: Datastore details with cluster name.

    Posted Aug 10, 2020 10:33 AM

    Super. Thank you....