This VI Toolkit script lists how many VMs are associated with each datastore. Additionally it shows datastore capacity, freespace, and % freespace.
It prompts for output file (which is HTML) when you run the script, and automatically loads the .html file aftwards.
This script can be way smaller. If you dont care about fancy HTML output (i know i do) and automacically launching the output file, just cut those sections out.
# Asks user for HTML output file
$strFile = (Read-Host "Enter full path to HTML output file:")
# Defines HEAD information for HTML formatting
$head = "<style>`n"
$head += "body {font-family: Verdana; font-size: 11px;}`n"
$head += "table {border-width: 1px;}`n"
$head += "td {border-width: 1px; padding: 2px; border-style: solid; border-color: #afafaf;}`n"
$head += "th {text-align: left;}`n"
$head += "</style>`n"
# Connect to VC
Connect-VIServer -Server <server_name>
# Gets datastores and creates empty array
$ds = Get-Datastore | Sort-Object Name | % { Get-View $_.ID }
$myCol = @()
# Loops thrue each entry and renames VM property
Foreach ($store in $ds)
{
$myObj = "" | Select-Object Datastore, VMs, "Size (GB)", "Free (GB)", "Free (%)"
$myObj."Datastore" = $store.Info.Name
$myObj."VMs" = $store.Vm.Length
$myObj."Size (GB)" = [math]::Round( ($store.Summary.Capacity/1GB),0 )
$myObj."Free (GB)" = [math]::Round( ($store.Summary.Freespace/1GB),0 )
$myObj."Free (%)" = [math]::Round( ($store.Summary.Freespace/$store.Summary.Capacity * 100),0 )
$myCol += $myObj
}
# Converts array output to HTML
$myCol | ConvertTo-Html -Head $head > $strFile
# Creats IE object, and launches the output file
$objIE = New-Object -com "InternetExplorer.Application"
$objIE.Navigate($strFile)
$objIE.ToolBar = 0
$objIE.StatusBar = 0
$objIE.Visible = $True
Remember to change the <server_name> value to your VC server IP/Hostname