Created
February 1, 2016 18:27
-
-
Save mattvanstone/79120b66c62301cae9c3 to your computer and use it in GitHub Desktop.
Get-DatastoreUsage PowerCLI Function - Get extended datastore provisioning information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .SYNOPSIS | |
| This function calculates useful values such as gigabytes provisioned, percent provisioned, percent free, and gigabytes over-provisioned for datastores. This information is not readily available using existing PowerCLI cmdlets or through the GUI. | |
| .DESCRIPTION | |
| Takes a datastore name or multiple datastore names as input and outputs datastore capacity, provisioned, free space, uncommitted, overcommitted, and percent free | |
| .PARAMETER datastore | |
| a datastore name (string) or multiple datastore names (using wildcards) | |
| .EXAMPLE | |
| Get-DatastoreUsage san-ds-01 | |
| .EXAMPLE | |
| Get-DatastoreUsage san-ds-0* | |
| #> | |
| Function Get-DatastoreUsage { | |
| [CmdletBinding()] Param( | |
| [Parameter(Mandatory=$True)][string]$datastore | |
| ) | |
| Process { | |
| $GB = [math]::pow(1024, 3) # Used to convert Bytes to Giga-Bytes in output | |
| $dss = Get-View -ViewType Datastore -Filter @{"Name"="$datastore"} | Select -ExpandProperty Summary | Select Name,Capacity,FreeSpace,Uncommitted | |
| $list = @() | |
| foreach ($ds in $dss) { | |
| $item = "" | Select Name,CapacityGB,ProvisionedGB,FreeSpaceGB,UncommittedGB,PercentProvisioned,OverProvisionedGB,PercentFree | |
| $item.Name = $ds.Name | |
| $item.CapacityGB = [decimal]("{0:N2}" -f ($ds.Capacity / $GB)) | |
| $item.ProvisionedGB = [decimal]("{0:N2}" -f (($ds.Capacity - $ds.FreeSpace + $ds.Uncommitted) / $GB)) | |
| $item.FreeSpaceGB = [decimal]("{0:N2}" -f ($ds.FreeSpace / $GB)) | |
| $item.UncommittedGB = [decimal]("{0:N2}" -f ($ds.Uncommitted / $GB)) | |
| $item.PercentProvisioned = [decimal]("{0:N2}" -f ($item.ProvisionedGB / $item.CapacityGB * 100)) | |
| $item.PercentFree = [decimal]("{0:N2}" -f ($ds.FreeSpace / $ds.Capacity * 100)) | |
| $item.OverProvisionedGB = [decimal]("{0:N2}" -f ("{0:N2}" -f (($ds.Uncommitted - $ds.FreeSpace) / $GB))) | |
| $list += $item | |
| } | |
| $list = $list | Sort Name | |
| } | |
| End { | |
| return $list | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use this function often to get quick stats on datastore usage. It is easy to see from the output if you have over provisioned some of your datastores too far or which datastores have underutilized space.