Enter your vCenter Server Name and Specify the output file name as per your wish. Both items are marked in yellow in the below script.
============================================================================================
Connect-VIServer vCENTER_SERVERNAME
Function Percentcal {
param(
[parameter(Mandatory = $true)]
[int]$InputNum1,
[parameter(Mandatory = $true)]
[int]$InputNum2)
$InputNum1 / $InputNum2*100
}
$datastores = Get-Datastore | Sort Name
ForEach ($ds in $datastores)
{
if (($ds.Name -match “Shared”) -or ($ds.Name -match “”))
{
$PercentFree = Percentcal $ds.FreeSpaceMB $ds.CapacityMB
$PercentFree = “{0:N2}” -f $PercentFree
$ds | Add-Member -type NoteProperty -name PercentFree -value $PercentFree
}
}
$datastores | Select Name,@{N=”UsedSpaceGB”;E={[Math]::Round(($_.ExtensionData.Summary.Capacity – $_.ExtensionData.Summary.FreeSpace)/1GB,0)}},@{N=”TotalSpaceGB”;E={[Math]::Round(($_.ExtensionData.Summary.Capacity)/1GB,0)}} ,PercentFree | Export-Csv c:\datastorereport.csv -NoTypeInformation
============================================================================================
Output of the above script will be similar to the below table. It will provide the Datastore name, UsedSpace in GB , TotalSpace in GB and % of free space on the datastore.
Name | UsedSpaceGB | TotalSpaceGB | PercentFree |
Prod_Datastore_T1_001 | 674 | 676 | 0.42 |
Prod_Datastore_T1_002 | 253 | 256 | 1.24 |
Prod_Datastore_T2_001 | 491 | 500 | 1.7 |
Prod_Datastore_T2_002 | 359 | 367 | 2.07 |
Dev_Datastore_001 | 250 | 256 | 2.18 |
Lab_Datastore_001 | 661 | 676 | 2.24 |
ISO_Datastore_001 | 2342 | 2397 | 2.28 |