-
Notifications
You must be signed in to change notification settings - Fork 2
/
Get-DatastoreProvisioned.ps1
61 lines (50 loc) · 2.5 KB
/
Get-DatastoreProvisioned.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function Get-DatastoreProvisioned {
<#
.SYNOPSIS
Retrieve the total thin provisioned space on each datastore.
.DESCRIPTION
Intended to reveal provisioned space alongside total/free space, to assist with svMotion decisions.
-Name should be supplied from the pipeline via Get-Datastore.
.EXAMPLE
Get-Datastore | Get-DatastoreProvisioned | Format-Table -AutoSize
View all datastores and view their capacity statistics in the current console.
.EXAMPLE
Get-Datastore -Name '*ssd' | Get-DatastoreProvisioned | Where-Object -Property ProvisionedPct -ge 100
For all datastores ending in 'ssd', return the capacity stats of those at least 100% provisioned.
.INPUTS
[VMware.VimAutomation.ViCore.Impl.V1.DatastoreManagement.VmfsDatastoreImpl]
Object type supplied by PowerCLI cmdlet Get-Datastore
.LINK
https://github.com/vmware/PowerCLI-Example-Scripts
.LINK
https://github.com/brianbunke
#>
[CmdletBinding()]
param (
# Specifies the datastore names to check. Tested only with pipeline input (see examples).
[Parameter(Mandatory = $true,
ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.Datastore]$Name
)
PROCESS {
If (-not $Name) {
Write-Warning '-Name cannot be empty. Terminating Get-DatastoreProvisioned.'
break
}
Write-Verbose "Get-DatastoreProvisioned processing '$($Name.Name)'"
# Calculate total provisioned space from the exposed properties
$Provisioned = ($Name.ExtensionData.Summary.Capacity -
$Name.ExtensionData.Summary.FreeSpace +
$Name.ExtensionData.Summary.Uncommitted) / 1GB
# Return info, wrapping it in the Math.Round method to trim to two decimal places
[PSCustomObject]@{
Name = $Name.Name
FreeSpaceGB = [math]::Round($Name.FreeSpaceGB, 2)
CapacityGB = [math]::Round($Name.CapacityGB, 2)
ProvisionedGB = [math]::Round($Provisioned, 2)
UsedPct = [math]::Round((($Name.CapacityGB - $Name.FreeSpaceGB) / $Name.CapacityGB) * 100, 2)
ProvisionedPct = [math]::Round(($Provisioned / $Name.CapacityGB) * 100, 2)
} #pscustomobject
} #process
} #function