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

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

Rate This
  • Comments 10

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

Attachment: DisplayCSVInfo2.txt
Leave a Comment
  • Please add 2 and 8 and type the answer here:
  • Post
  • Good post, I like the free space to be query-able through my sql instances so I have implemented a simple CLR function to do the same (which I might write a blog entry for) but it is always good to have several options to perform different tasks.

    Thanks.

    Mark Broadbent (aka retracement)

  • It looks interesting.  Microsoft should use this kind of scripts to be able to monitor a CSV volume by using Operations Manager.  I have this problem now, that Operations Manager is unable to send alerts because it can monitor disks, but not CSV disks.  I hope that they update the Management Pack and integrate this kind of very useful alerts.  

  • Hello,

    Nice script.

    Is it possible to extend the Query with   related infos to the Physicaldisk?

    because now i know the Cluster Volumes and the Cluster DIsk.  But which PhyiscalDisk is behind them ;)

    Because ClusterDisk1 must not be PhysicalDisk1 inside the Disk Manager

    thx

    Markus

  • Its pretty Cool..Ahmed Bisht..

    I have a query, regarding automation of Failover Cluster...Do you have any Script to automate the failover cluster 2008. if yes please

    Thanks

    Regards

  • Hi Jose,

    Great comment about monitoring CSV with Ops Manager (System Center Operatations Manager). Here is an article on this topic by Kevin Holman:

    blogs.technet.com/.../opsmgr-new-base-os-mp-6-0-6956-0-adds-cluster-shared-volume-monitoring-bpa-and-many-changes.aspx

    Thanks, Jose!

    -Rob.

  • Thank you for a great script!

    How can I call PercentFree as a variable? I would like to format it and display it like 65.42GB free in a WRITE-HOST. Can this be done?

    Keep up the excellent work!

  • I Need put this information in monitoring Nagios.

    How i do this?

  • can u possibly explain how use this remotely "against" the target server holding the CSV?

  • @roy - I posted a modified version of this script that can be run on a different machine than the Hyper-V host.

    social.technet.microsoft.com/.../e409f39d-81d7-4618-8dc2-abf5085822ed

  • The script is not available..  :/

Page 1 of 1 (10 items)