PowerCLI-Example-Scripts
PowerCLI-Example-Scripts copied to clipboard
VAMI function Get-VAMIStorageUsed 6.7 compatibility
Looks like a number of the partition names have changed in 6.7 VAMI API such that Get-VAMIStorageUsed is broken.
$querySpec.Names and $storageStats are affected
Removed in 6.7 invsvc
Changed Name in 6.7 vcdb_seat is now seat vcdb_core_inventory is now db vcdb_transaction_log is now dblog coredump is now core
New in 6.7 archive
I am not well-versed in writing modules, so I am not sure if the preference would be to have a new module to support 6.7, or to put logic in this module to detect the vSphere version, but in either case this is the updated function code that works correctly on 6.7
Function Get-VAMIStorageUsed {
<#
.NOTES
===========================================================================
Created by: William Lam
Organization: VMware
Blog: www.virtuallyghetto.com
Twitter: @lamw
===========================================================================
.SYNOPSIS
This function retrieves the individaul OS partition storage utilization
for a VCSA node which can be an Embedded VCSA, External PSC or External VCSA.
.DESCRIPTION
Function to return individual OS partition storage utilization
.EXAMPLE
Connect-CisServer -Server 192.168.1.51 -User [email protected] -Password VMware1!
Get-VAMIStorageUsed
#>
$monitoringAPI = Get-CisService 'com.vmware.appliance.monitoring'
$querySpec = $monitoringAPI.help.query.item.CreateExample()
# List of IDs from Get-VAMIStatsList to query
$querySpec.Names = @(
"storage.used.filesystem.archive",
"storage.used.filesystem.autodeploy",
"storage.used.filesystem.boot",
"storage.used.filesystem.core",
"storage.used.filesystem.imagebuilder",
"storage.used.filesystem.log",
"storage.used.filesystem.netdump",
"storage.used.filesystem.root",
"storage.used.filesystem.updatemgr",
"storage.used.filesystem.db",
"storage.used.filesystem.seat",
"storage.used.filesystem.dblog",
"storage.totalsize.filesystem.archive",
"storage.totalsize.filesystem.autodeploy",
"storage.totalsize.filesystem.boot",
"storage.totalsize.filesystem.core",
"storage.totalsize.filesystem.imagebuilder",
"storage.totalsize.filesystem.log",
"storage.totalsize.filesystem.netdump",
"storage.totalsize.filesystem.root",
"storage.totalsize.filesystem.updatemgr",
"storage.totalsize.filesystem.db",
"storage.totalsize.filesystem.seat",
"storage.totalsize.filesystem.dblog"
)
# Tuple (Filesystem Name, Used, Total) to store results
$storageStats = @{
"archive"=@{"name"="/storage/archive";"used"=0;"total"=0};
"autodeploy"=@{"name"="/storage/autodeploy";"used"=0;"total"=0};
"boot"=@{"name"="/boot";"used"=0;"total"=0};
"core"=@{"name"="/storage/core";"used"=0;"total"=0};
"imagebuilder"=@{"name"="/storage/imagebuilder";"used"=0;"total"=0};
"log"=@{"name"="/storage/log";"used"=0;"total"=0};
"netdump"=@{"name"="/storage/netdump";"used"=0;"total"=0};
"root"=@{"name"="/";"used"=0;"total"=0};
"updatemgr"=@{"name"="/storage/updatemgr";"used"=0;"total"=0};
"db"=@{"name"="/storage/db";"used"=0;"total"=0};
"seat"=@{"name"="/storage/seat";"used"=0;"total"=0};
"dblog"=@{"name"="/storage/dblog";"used"=0;"total"=0}
}
$querySpec.interval = "DAY1"
$querySpec.function = "MAX"
$querySpec.start_time = ((get-date).AddDays(-1))
$querySpec.end_time = (Get-Date)
$queryResults = $monitoringAPI.query($querySpec) | Select * -ExcludeProperty Help
foreach ($queryResult in $queryResults) {
# Update hash if its used storage results
if($queryResult.name -match "used") {
$key = (($queryResult.name).toString()).split(".")[-1]
$value = [Math]::Round([int]($queryResult.data[1]).toString()/1MB,2)
$storageStats[$key]["used"] = $value
# Update hash if its total storage results
} else {
$key = (($queryResult.name).toString()).split(".")[-1]
$value = [Math]::Round([int]($queryResult.data[1]).toString()/1MB,2)
$storageStats[$key]["total"] = $value
}
}
$storageResults = @()
foreach ($key in $storageStats.keys | Sort-Object -Property name) {
$statResult = [pscustomobject] @{
Filesystem = $storageStats[$key].name;
UsedGb = $storageStats[$key].used;
TotalSizeGb = $storageStats[$key].total
}
$storageResults += $statResult
}
$storageResults
}