VMware Cloud Community
nava_thulasi39
Jump to solution

Need a script for Datastore free space details

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 find this or any other answer useful please consider awarding points by marking the answer correct or helpful
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

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.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
5 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

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

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
nava_thulasi39
Jump to solution

Thanks RvdNieuwendijk.

It works perfectly.

But could you please fine tune it to create a report as in .csv file.

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

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.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

nava_thulasi39
Jump to solution

Great. works perfect.

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
0 Kudos