PowerShell for Failover Clustering: CSV Free Disk Space (and other info)

Hi Cluster PowerShell script writers,

We regularly get asked about how to find the free disk space on Cluster Shared Volumes (CSV). In this blog, I will show you how to do this with PowerShell.

Here are the CSV volumes in my cluster. Note that Cluster Disk 10 has two partitions.

 

To find the free disk space through PowerShell, the information is available inside the objects returned by Get-ClusterSharedVolume. You can easily see that information by piping the output to Format-Custom: PS> Get-ClusterSharedVolume “Cluster Disk 1″ | fc *


Here is an example. Note that I’m just getting this information for one CSV disk (Cluster Disk 1), but you can also get it for all CSVs on the cluster by running:
PS > Get-ClusterSharedVolume | fc *


Now let’s look at the full output:

PS C:\> Get-ClusterSharedVolume “Cluster Disk 1″ | fc *

 

class ClusterSharedVolume

{

  Name = Cluster Disk 1

  State = Online

  OwnerNode =

    class ClusterNode

    {

      Name = ahmedbc1-n2

      State = Up

    }

  SharedVolumeInfo =

    [

      class ClusterSharedVolumeInfo

      {

        FaultState = NoFaults

        FriendlyVolumeName = C:\ClusterStorage\Volume2

        Partition =

          class ClusterDiskPartitionInfo

          {

            Name = \\?\Volume{ef349066-525c-11df-8261-001e4fe757b6}

            DriveLetter =

            DriveLetterMask = 0

            FileSystem = NTFS

            FreeSpace = 17665183744

            MountPoints =

              [

              ]

            PartitionNumber = 1

            PercentFree = 84.24681

            Size = 20968370176

            UsedSpace = 3303186432

            HasDriveLetter = False

            IsCompressed = False

            IsDirty = Unknown

            IsFormatted = True

            IsNtfs = True

            IsPartitionNumberValid = True

            IsPartitionSizeValid = True

          }

        PartitionNumber = 1

        VolumeOffset = 1048576

        MaintenanceMode = False

        RedirectedAccess = False

      }

    ]

  Id = 3b115c10-95ab-4420-8e58-da1d988c7750

}

 

As you see, the information is not easy to find because you have to look through the nested objects and the default formatting is not nice. For example, I’m sure you want to see the size in GB not bytes!


Here is a “one line” command that gives you some information:

PS C:\> Get-ClusterSharedVolume | select -Expand SharedVolumeInfo | select -Expand Partition | ft -a

uto Name,@{ 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” ; Expre

ssion = { “{0:N2}” -f ($_.PercentFree) } }

 

Name                                             Size(GB) FreeSpace(GB) UsedSpace(GB) PercentFree

—-                                             ——– ————- ————- ———–

\\?\Volume{ef349066-525c-11df-8261-001e4fe757b6} 19.53    16.45         3.08          84.25

\\?\Volume{297b7d61-62d5-11df-91ff-001e4fe757b6} 0.49     0.46          0.03          93.95

\\?\Volume{297b7d68-62d5-11df-91ff-001e4fe757b6} 0.49     0.46          0.03          93.91

\\?\Volume{ef349070-525c-11df-8261-001e4fe757b6} 19.53    19.44         0.09          99.55

\\?\Volume{ef34907a-525c-11df-8261-001e4fe757b6} 19.53    15.78         3.75          80.80

\\?\Volume{ef3490a2-525c-11df-8261-001e4fe757b6} 0.97     0.93          0.04          95.91

 

The problem with this is that it does not give you the friendly name given the nested nature of the objects returned with Get-ClusterSharedVolume. To do a better job displaying the information, I created this script that will display the information in a better view, which is attached to this blog post.  Please download the DisplayCSVInfo2.txt file and rename it as a DisplayCSVInfo.ps1 file.  This is an unsupported script by Microsoft and should be used at your own risk.

PS C:\> .\DisplayCSVInfo.ps1

 

Name            Path                      Size(GB) FreeSpace(GB) UsedSpace(GB) PercentFree

—-            —-                      ——– ————- ————- ———–

Cluster Disk 1  C:\ClusterStorage\Volume2 19.53    16.45         3.08          84.25

Cluster Disk 10 C:\ClusterStorage\Volume6 0.49     0.46          0.03          93.95

Cluster Disk 10 C:\ClusterStorage\Volume7 0.49     0.46          0.03          93.91

Cluster Disk 2  C:\ClusterStorage\Volume3 19.53    19.44         0.09          99.55

Cluster Disk 3  C:\ClusterStorage\Volume4 19.53    15.78         3.75          80.80

Cluster Disk 7  C:\ClusterStorage\Volume5 0.97     0.93          0.04          95.91

Happy scripting!

Regards,


Ahmed Bisht

Senior Program Manager

Clustering & High-Availability

Microsoft

DisplayCSVInfo2.txt