Hi
I have written the below script, but don't how to add and get the cluster name with respective to the datastore, also need to add sum of UsableFreeSpace in cluster wise.
Any help would be appreciable please.
$report = @()
Connect-VIServer -Server VCServer
$date = Get-Date -Format 'yyyyMMdd'
$datastores = Get-Datastore | where {$_.Type -eq "VMFS"}
foreach($store in $datastores){
$storeinfo = "" | Select DatastoreName, CapacityGB, FreeSpaceGB, FreeSpaceInPercent, UsableFreeSpace
$datastoreview = get-datastore -Name $store.Name | Get-View | select -ExpandProperty summary
$CapacityGB = [math]::round($datastoreview.Capacity/1GB,2)
$FreeSpaceGB = [math]::round($datastoreview.FreeSpace/1GB,2)
$Percent = [math]::round(($datastoreview.FreeSpace/$datastoreview.Capacity) * 100)
$Usable = [math]::round((($datastoreview.FreeSpace) - ($datastoreview.Capacity/2))/1GB,2)
$storeinfo.DatastoreName = $store.Name
$storeinfo.CapacityGB = $CapacityGB
$storeinfo.FreeSpaceGB = $FreeSpaceGB
$storeinfo.FreeSpaceInPercent = $Percent
$storeinfo.UsableFreeSpace = if($Percent -ge 55) { $Usable } else { 'Not enough space'}
$report += $storeinfo
}
$report | Export-CSV -Path "D:\Datastore_Report_$date.csv" -NoTypeInformation -UseCulture
Disconnect-VIServer -Server VCServer -Confirm:$false
Thanks in advance,