-
Notifications
You must be signed in to change notification settings - Fork 6
/
Get-VmfsDatastore
62 lines (44 loc) · 2.58 KB
/
Get-VmfsDatastore
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
62
Function Get-VMFSDatastore {
param(
[parameter(position=0,ValueFromPipeline=$True,ValueFromPipelineByPropertyname=$True)]
[VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.VmfsDatastore[]]
$Datastore = (Get-Datastore | where type -eq VMFS)
)
Process{
ForEach ($DS in $Datastore) {
if ($ds.type -eq "VMFS") {
# Check if the datastore is expandable.
if ($ds.Accessible) {
$hostId = [string]($ds.ExtensionData.Host | where {$_.mountinfo.Accessible -and $_.mountinfo.Mounted} | select -ExpandProperty key -First 1)
$DsHostDsView = get-view $hostId -Property ConfigManager.DatastoreSystem
$DsHostDsView = get-view $DsHostDsView.ConfigManager.DatastoreSystem
$Expandable = $DsHostDsView.QueryVmfsDatastoreExpandOptions($ds.id)
if ($Expandable.count -eq 0) {$Expandable = $false}
else {
$LunSize = ($Expandable.info.VmfsExtent.end.block - $Expandable.info.VmfsExtent.start.block) * $Expandable.info.VmfsExtent.start.blocksize / 1GB
$FreeSpaceOnLun = [math]::round($LunSize - $ds.CapacityGB,2)
$Expandable = "+$($FreeSpaceOnLun)GB"
}
} else {$Expandable = $false}
# Process capacity and provisioning data.
$CapacityGB = [Math]::Round(($ds.extensiondata.summary.capacity / 1GB),2)
$FreeGB = [Math]::Round(($ds.extensiondata.summary.FreeSpace / 1GB),2)
$UsedGB = [Math]::Round((($ds.extensiondata.summary.capacity / 1GB) - ($ds.extensiondata.summary.FreeSpace / 1GB)),2)
$ProvisionedGB = [Math]::Round((($ds.extensiondata.summary.capacity / 1GB) - ($ds.extensiondata.summary.FreeSpace / 1GB) + ($ds.extensiondata.summary.Uncommitted / 1GB)),2)
$ProvisionedPercent = [Math]::Round($ProvisionedGB / $CapacityGB * 100,1)
[pscustomobject]@{
Name = $ds.name
Accessible = $ds.Accessible
CapacityGB = $CapacityGB
FreeSpaceGB = $FreeGB
FreeSpace = "$([math]::round($FreeGB / $CapacityGB * 100,1))%"
UsedSpaceGB = $UsedGB
ProvisionedGB = $ProvisionedGB
Provisioned = "$ProvisionedPercent%"
NbRunningVMs = ($ds | Get-VM | where powerstate -eq Poweredon).count
Expandable = $Expandable
}
} else {"$($Datastore.name) is not a VMFS datastore"}
}
}
}