Automation

 View Only
Expand all | Collapse all

Datastore report-Powercli script

  • 1.  Datastore report-Powercli script

    Posted Jul 13, 2019 08:15 AM

    Hi All,

    I am looking for a script which can fetch datastore usage in percentage. i have one script and i am getting the report as below in percentage free space, instead i need the data in percentage with total usage in percentage.

    DataStoreNamePercentage Free Space(%)
    datastore192.07
    datastore271.59
    datastore371.6
    datastore475.19

    thanks in advance



  • 2.  RE: Datastore report-Powercli script
    Best Answer

    Posted Jul 13, 2019 08:20 AM

    Try like this

    Get-Datastore |

    Select Name,

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

    ---------------------------------------------------------------------------------------------------------

    Was it helpful? Let us know by completing this short survey here.



  • 3.  RE: Datastore report-Powercli script

    Posted Jul 15, 2019 04:22 PM

    Thank you very mush  LucD,

    One more thing, can we add below script with the percentage usage :

    get-datastore | select-object name,@{Label=”FreespaceGB”;E={“{0:n2}” -f ($_.FreespaceGB)}}, CapacityGB, @{Label=”Provisioned”;E={“{0:n2}” -f ($_.CapacityGB – $_.FreespaceGB +($_.extensiondata.summary.uncommitted/1GB))}}|sort name | export-csv datastores.csv

    So that i  could get the below output:

    NameFreespaceGBCapacityGBProvisionedUsed Space %

    thanks

    prateek



  • 4.  RE: Datastore report-Powercli script

    Posted Jul 15, 2019 04:45 PM

    Sure, but that is just adding properties on the same Select-Object.

    Like this

    Get-Datastore |

    Select Name,

       @{N=”FreespaceGB”;E={{0:n2}-f ($_.FreespaceGB)}},

      CapacityGB,

       @{N=”Provisioned”;E={{0:n2}-f ($_.CapacityGB$_.FreespaceGB +($_.extensiondata.summary.uncommitted/1GB))}},

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



  • 5.  RE: Datastore report-Powercli script

    Posted Dec 23, 2019 12:11 PM

    Hi LucD,

    I tried below script but it throws an error

    PS D:\vmk> .\Datastore.ps1

    At D:\vmk\Datastore-freespace.ps1:1 char:5

    + $Get-Datastore |

    +     ~~~~~~~~~~

    Unexpected token '-Datastore' in expression or statement.

        + CategoryInfo          : ParserError: (:) [], ParseException

        + FullyQualifiedErrorId : UnexpectedToken

    thanks

    vmk



  • 6.  RE: Datastore report-Powercli script

    Posted Dec 23, 2019 01:09 PM

    That dollar-sign ($) in front of Get-Datastore shouldn't be there



  • 7.  RE: Datastore report-Powercli script

    Posted Jan 04, 2020 06:34 AM

    LucD,

    Sorry for late reply. i'll check and will let you know. But if want to know the specific data store utilization example _VMAX_WIN and Oracle_VMAX_ then how to get the report for utilization and % percentage free. Kindly help me

    thanks

    v



  • 8.  RE: Datastore report-Powercli script

    Posted Jan 04, 2020 08:32 AM

    You can use the Name parameter on the Get-Datastore cmdlet.

    $dsNames = '*_VMAX_WIN*','*Oracle_VMAX_*'

    Get-Datastore -Name $dsNames |

    Select Name,

       @{N=”FreespaceGB”;E={{0:n2}-f ($_.FreespaceGB)}},

      CapacityGB,

       @{N=”Provisioned”;E={{0:n2}-f ($_.CapacityGB$_.FreespaceGB +($_.extensiondata.summary.uncommitted/1GB))}},

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



  • 9.  RE: Datastore report-Powercli script

    Posted Jan 05, 2020 06:50 PM

    LucD,

    it's working fine. is it possible to add % free space along with data used % (already added) ?

    thanks

    v



  • 10.  RE: Datastore report-Powercli script

    Posted Jan 05, 2020 07:29 PM

    Try like this

    $dsNames = '*_VMAX_WIN*','*Oracle_VMAX_*'

    Get-Datastore -Name $dsNames |

    Select Name,

       @{N=”FreespaceGB”;E={{0:n2}-f ($_.FreespaceGB)}},

       CapacityGB,

       @{N=”Provisioned”;E={{0:n2}-f ($_.CapacityGB$_.FreespaceGB +($_.extensiondata.summary.uncommitted/1GB))}},

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

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



  • 11.  RE: Datastore report-Powercli script

    Posted Mar 19, 2020 06:51 AM

    Hi LucD,

    When i tried to export into csv format but it throws an error. Any idea why ?

    Get-Datastore |

    Select Name,

       @{N=”FreespaceGB”;E={“{0:n2}” -f ($_.FreespaceGB)}},

      CapacityGB,

       @{N=”Provisioned”;E={“{0:n2}” -f ($_.CapacityGB – $_.FreespaceGB +($_.extensiondata.summary.uncommitted/1GB))}},

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

    $report | Export-Csv -path c:\Temp\dsreport-Marc19.csv

    Thanks

    V



  • 12.  RE: Datastore report-Powercli script

    Posted Mar 19, 2020 07:00 AM

    I'm not sure why you are using the $report variable, but try like this

    Get-Datastore |

    Select-Object Name,

        @{N = ”FreespaceGB”; E = {{0:n2}-f ($_.FreespaceGB) } },

        CapacityGB,

        @{N = ”Provisioned”; E = {{0:n2}-f ($_.CapacityGB$_.FreespaceGB + ($_.extensiondata.summary.uncommitted / 1GB)) } },

        @{N = 'Used Space(%)'; E = { [math]::Round((($_.CapacityGB - $_.FreeSpaceGB) / $_.CapacityGB * 100), 1) } } |

    Export-Csv -path c:\Temp\dsreport-Marc19.csv



  • 13.  RE: Datastore report-Powercli script

    Posted Mar 19, 2020 07:50 AM

    Thank LucD. It worked for me