With the failover cluster manager it’s hard to summarize the free space for each CSV.
Here is a sample script to determine the free space for the Cluster Shared Volumes in each Hyper-V cluster.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
Import-Module FailoverClusters $objs = @() $csvs = @() $Clusters = ("CL99-HPV","CL4-HPV","CL5-HPV") #Get CSVs foreach cluster foreach($Clu in $Clusters){ $c = Get-ClusterSharedVolume -Cluster $Clu $csvs += $c } #Get CSV Info 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 } } $objs |Sort-Object freespace | 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) }} |
Found an issue with your code. $csvs += $c should be included in the foreach loop above it. Otherwise you’re only getting data from the last cluster in the array.
Thanks for sharing your code.
Jim
Thanks for sharing.
I Will edit my code.
I corrected and added the code, in my opinion it turned out more beautiful
—————————–
$objs = @()
$Clusters = (“clu210″,”clu230″,”clu200”)
#Get CSVs foreach cluster
foreach($Clu in $Clusters){
$c = Get-ClusterSharedVolume -Cluster $Clu
#Get CSV Info
foreach ( $csv in $c )
{
$csvinfos = $csv | select -Property Name -ExpandProperty SharedVolumeInfo
foreach ( $csvinfo in $csvinfos )
{
$obj = New-Object PSObject -Property @{
Clustername = $Clu
Name = $csv.Name
Owner = $csv.OwnerNode
Path = $csvinfo.FriendlyVolumeName
Size = $csvinfo.Partition.Size
FreeSpace = $csvinfo.Partition.FreeSpace
UsedSpace = $csvinfo.Partition.UsedSpace
PercentFree = $csvinfo.Partition.PercentFree
}
$objs += $obj
}
}
}
$objs |Sort-Object Clustername | ft -auto Clustername,Name, Owner, 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) }}
Mike,
Thanks for your beautiful code. It is just what I needed. This really helps us non-programmer types.