Automation

 View Only
  • 1.  Thin Provision Report

    Posted Sep 15, 2011 04:04 PM

    I'm looking for a powercli script and I'm guessing someone has already written this.

    I would like a total of our datastore capacity, a total of all disk space provisioned to VMs and a total of what the VMs are actually using on the datastore.

    I'm a noob to powershell and this currently exceeds my skills.

    Natasha



  • 2.  RE: Thin Provision Report
    Best Answer

    Posted Sep 15, 2011 04:42 PM

    Hello, LeaV97-

    You are correct, there are a few scripts out there that get datastore info as you requested.  I took this opportunity to write a fresh one, with speed in mind:

    ## get the sums of the given properties for all datastores
    $arrSums = Get-View -ViewType Datastore -Property Summary | %{$_.Summary} | Measure-Object -Property Capacity, FreeSpace, Uncommitted -Sum
    ## separate out the sums to separate variables for calculations later
    $fltCapacityGB = ($arrSums | ?{$_.Property -eq "Capacity"}).Sum / 1GB
    $fltFreeGB = ($arrSums | ?{$_.Property -eq "FreeSpace"}).Sum / 1GB
    $fltUncommittedGB = ($arrSums | ?{$_.Property -eq "Uncommitted"}).Sum / 1GB

    New-Object -TypeName PSObject -Property @{
       
    ## the total capacity of the datastores
        CapacityGB = [Math]::round($fltCapacityGB, 1)
       
    ## the amount of space used by VMs
        UsedGB = [Math]::round(($fltCapacityGB - $fltFreeGB), 1)
       
    ## the amount of space provisioned to VMs
        ProvisionedGB = [Math]::round(($fltCapacityGB - $fltFreeGB + $fltUncommittedGB), 1)
    }
    ## end new-object

    This uses the Get-View and Measure-Object cmdlets to get the info, and returns an object with the three pieces of info that you requested.



  • 3.  RE: Thin Provision Report

    Posted Sep 15, 2011 05:25 PM

    I made a little modification and added a Where-Object {$_.MultipleHostAccess -eq "True"} to screen out the local storage.



  • 4.  RE: Thin Provision Report

    Posted Sep 16, 2011 03:34 AM

    Nice addition for environments with local datastores (presumably unused, so not wanted in the results), LeaV97.

    A note about that:  there is also the option to add a -Filter parameter to the initial Get-View command.  It does not make much of a speed difference in this example, but there are situations where that method would be preferable (for speed and for memory usage benefites).

    Using -Filter on Get-View results in the filtering taking place on the server side, so the "unwanted" objects are not even returned to the PowerCLI session, whereas going the Where-Object route filters out objects on the client side, _after_ they have already been returned to the client, and the time/memory price has been paid.  Just wanted to add that tidbit.