PowerShell: List CSV Free/Used Capacity plus totals

This script will recursively list all the cluster shared volumes and give free/used/total data for them all.

I can't claim to have written this, but i did add the handy "Total Space" and & "Total Free space" bits at the end, which if you ask me, are the best bits.


Import-Module FailoverClusters

$objs = @()
$csvs = Get-ClusterSharedVolume
$totalFreeSp = 0
$totalSpFreeFreindly = 0
$TotalSp =0
$TotalSpFreindly = 0
foreach ( $csv in $csvs )
{
   $csvinfos = $csv | select -Property Name -ExpandProperty SharedVolumeInfo
   foreach ( $csvinfo in $csvinfos )
   {
      $obj = New-Object PSObject -Property @{
         Name        = $csv.Name
         Path        = $csvinfo.FriendlyVolumeName
         Size        = $csvinfo.Partition.Size
         FreeSpace   = $csvinfo.Partition.FreeSpace
         UsedSpace   = $csvinfo.Partition.UsedSpace
         PercentFree = $csvinfo.Partition.PercentFree
         
        
      }
      $objs += $obj
      $TotalSp = $csvinfo.Partition.Size + $TotalSp
      $totalFreeSp = $csvinfo.Partition.FreeSpace + $totalFreeSp
      
   }
}

$objs | ft -auto Name,Path,@{ Label = "Size(GB)" ; Expression = { "{0:N2}" -f ($_.Size/1024/1024/1024) } },@{ Label = "FreeSpace(GB)" ; Expression = { "{0:N2}" -f ($_.FreeSpace/1024/1024/1024) } },@{ Label = "UsedSpace(GB)" ; Expression = { "{0:N2}" -f ($_.UsedSpace/1024/1024/1024) } },@{ Label = "PercentFree" ; Expression = { "{0:N2}" -f ($_.PercentFree) } }

$totalSpFreeFreindly = ($totalFreeSp/1024/1024/1024/1024)
$totalSpFreeFreindly = [math]::Round($totalSpFreeFreindly,2)
$TotalSpFreindly = ($TotalSp/1024/1024/1024/1024)
$TotalSpFreindly = [math]::Round($TotalSpFreindly,2)

("Total Space =" + $TotalSpFreindly + "TB     " +  "Total Free Space= "+ $totalSpFreeFreindly + "TB     ")