Automation

 View Only
  • 1.  Need a script for Datastore free space details

    Posted Jul 07, 2011 12:10 PM

    Hi,

    I need a script to get Datstore name, Capacity in GB and free space in GB based on each cluster.

    Thanks in advance.



  • 2.  RE: Need a script for Datastore free space details

    Posted Jul 07, 2011 12:16 PM

    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



  • 3.  RE: Need a script for Datastore free space details

    Posted Jul 07, 2011 12:46 PM

    Thanks RvdNieuwendijk.

    It works perfectly.

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



  • 4.  RE: Need a script for Datastore free space details
    Best Answer

    Posted Jul 07, 2011 12:52 PM

    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.



  • 5.  RE: Need a script for Datastore free space details

    Posted Jul 07, 2011 12:57 PM

    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


  • 6.  RE: Need a script for Datastore free space details

    Posted Jul 07, 2011 02:04 PM

    Great. works perfect.