Skip to content

Instantly share code, notes, and snippets.

@meoso
Last active January 26, 2022 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meoso/1b3b45a904d4fb8c77d31f21bcafc252 to your computer and use it in GitHub Desktop.
Save meoso/1b3b45a904d4fb8c77d31f21bcafc252 to your computer and use it in GitHub Desktop.
VMWare DataStore Statistics
[CmdletBinding()]
param(
[Parameter(Mandatory=$True,Position=0,HelpMessage="The script will output to .CSV datastore statistics for the provided vCenter Server hostname or FQDN")]
[string]$vCenter
)
Import-Module VMware.VimAutomation.Core | Out-Null
try {
Connect-VIServer -Server $vCenter -Protocol https -Force -ErrorVariable err -ErrorAction SilentlyContinue | Out-Null
} catch {
Out-Null
} finally {
if ($err.Count -eq 0) {
Write-Output "Fetching DataStore statistics..."
$datastores = get-datastore
$report = foreach ($store in $datastores) {
$store | Select @{N='Datacenter';E={$_.Datacenter.Name}},
@{N='DSCluster';E={Get-DatastoreCluster -Datastore $_ | Select -ExpandProperty Name}},
Name,CapacityGB,@{N='FreespaceGB';E={[math]::Round($_.FreespaceGB,2)}},
@{N='VMCount';E={$_.ExtensionData.VM.Count}},
@{N='ProvisionedSpaceGB';E={[math]::Round(($_.ExtensionData.Summary.Capacity - $_.Extensiondata.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2)}},
@{N='UnCommittedGB';E={[math]::Round($_.ExtensionData.Summary.Uncommitted/1GB,2)}},
@{N='FreeGB/CapacityGB %';E={[math]::Round(($_.FreespaceGB/$_.CapacityGB)*100,2 -f 000.00)}},
@{N='ProvisionedGB/CapacityGB %';E={[math]::Round(($_.ExtensionData.Summary.Capacity - $_.Extensiondata.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/$_.CapacityGB/1GB*100,2 -f 000.00)}}
}
$report | Sort-Object -Property 'ProvisionedGB/CapacityGB %' | Export-Csv datastore-stats.CSV -NoTypeInformation -UseCulture
ls datastore-stats.CSV
disconnect-viserver -Confirm:$false
} else {
Write-Output "failed to connect to ${vCenter}. Exiting."
Exit
}
}
@meoso
Copy link
Author

meoso commented Jan 26, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment