VMware Cloud Community
LeaV97
Enthusiast
Enthusiast
Jump to solution

Thin Provision Report

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

Reply
0 Kudos
1 Solution

Accepted Solutions
mattboren
Expert
Expert
Jump to solution

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.

View solution in original post

Reply
0 Kudos
3 Replies
mattboren
Expert
Expert
Jump to solution

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.

Reply
0 Kudos
LeaV97
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
mattboren
Expert
Expert
Jump to solution

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.