This is my second post and I was recently requested by one of my colleagues to help him with a report which shows Datastores, Capacity, Freespace along with the cluster name and hosts that it is connected to. This can connect to multiple vCenters and push separate reports for each of the vCenter.
$vcservers = "vc1.company.com", "vc2.company.com"
foreach($vcserver in $vcservers){
Connect-VIServer $vcserver -Port 443
$report = @()
$DS = Get-Datastore | Where {$_.Type -eq "VMFS" -and $_.Extensiondata.Summary.MultipleHostAccess} | Sort Name
foreach ($store in $DS){
$memberhosts = ($store | Get-VMHost | Select -ExpandProperty Name) -join ","
$cluster = ($store | Get-VMHost | Sort Name | Select -First 1 | Get-Cluster).Name
$list = "" | Select-Object Name, CapacityGB, FreeGB, PercFree, FileSystem, ClusterName, MemberHosts
$list.Name = $store.Name
$list.CapacityGB = "{0:N2}" -f ($store.capacityMB/1kb)
$list.FreeGB = "{0:n2}" -f ($store.FreeSpaceMB/1kb)
$list.PercFree = "{0:N2}" -f (100 * $store.FreeSpaceMB/$store.CapacityMB)
$list.FileSystem = $store.Type
$list.ClusterName = $cluster
$list.MemberHosts = $memberhosts
$report += $list
}
$report | Export-Csv "C:\Temp\Output\$vcserver.csv" -NoTypeInformation
Disconnect-VIServer $vcserver -Confirm:$false
Clear-Variable report
}
Sample output below --
There could be much easier ways to do this, but this one just worked out for me.
$vcservers = "vc1.company.com", "vc2.company.com"
foreach($vcserver in $vcservers){
Connect-VIServer $vcserver -Port 443
$report = @()
$DS = Get-Datastore | Where {$_.Type -eq "VMFS" -and $_.Extensiondata.Summary.MultipleHostAccess} | Sort Name
foreach ($store in $DS){
$memberhosts = ($store | Get-VMHost | Select -ExpandProperty Name) -join ","
$cluster = ($store | Get-VMHost | Sort Name | Select -First 1 | Get-Cluster).Name
$list = "" | Select-Object Name, CapacityGB, FreeGB, PercFree, FileSystem, ClusterName, MemberHosts
$list.Name = $store.Name
$list.CapacityGB = "{0:N2}" -f ($store.capacityMB/1kb)
$list.FreeGB = "{0:n2}" -f ($store.FreeSpaceMB/1kb)
$list.PercFree = "{0:N2}" -f (100 * $store.FreeSpaceMB/$store.CapacityMB)
$list.FileSystem = $store.Type
$list.ClusterName = $cluster
$list.MemberHosts = $memberhosts
$report += $list
}
$report | Export-Csv "C:\Temp\Output\$vcserver.csv" -NoTypeInformation
Disconnect-VIServer $vcserver -Confirm:$false
Clear-Variable report
}
Sample output below --
There could be much easier ways to do this, but this one just worked out for me.