Hi,
I need a script to get Datstore name, Capacity in GB and free space in GB based on each cluster.
Thanks in advance.
If you change the last line of the script into:
} | Export-Csv -Path Datastores.csv -NoTypeInformation -UseCulture
it will write the output to a file called Datastores.csv.
The next PowerCLI script will give you the datastore name, capacity in GB and free space in GB for all datastores.
Get-Datastore | ` Sort-Object -Property Name | ForEach-Object { $Datastore = $_ $Report = "" | Select-Object -Property Datastore,CapacityGB,FreeSpaceGB $Report.Datastore = $Datastore.Name $Report.CapacityGB = [Math]::Round($_.CapacityMB/1KB,0) $Report.FreeSpaceGB = [Math]::Round($_.FreeSpaceMB/1KB,0) $Report }
Regards, Robert
Thanks RvdNieuwendijk.
It works perfectly.
But could you please fine tune it to create a report as in .csv file.
If you change the last line of the script into:
} | Export-Csv -Path Datastores.csv -NoTypeInformation -UseCulture
it will write the output to a file called Datastores.csv.
Per cluster and to a CSV file
$report = @() foreach($cluster in Get-Cluster){ Get-Datastore -VMHost (Get-VMHost -Location $cluster | Select -First 1) | `
Sort-Object -Property Name | ForEach-Object { $row = "" | Select-Object -Property Cluster, Datastore,CapacityGB,FreeSpaceGB $row.Cluster = $cluster.Name $row.Datastore = $_.Name $row.CapacityGB = [Math]::Round($_.CapacityMB/1KB,0) $row.FreeSpaceGB = [Math]::Round($_.FreeSpaceMB/1KB,0) $Report += $row
} } $report | Export-Csv "C:\ds-report.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Great. works perfect.