Powershell command to retrieve Failover Cluster Disk Size/Free Space?

sm_biz picture sm_biz · Jul 22, 2013 · Viewed 12.8k times · Source

I'm using Powershell and attempting to retrieve the size, and available space, of a Physical Disk Resource.

I want this code to run on one Windows Server 2008 R2 box (a monitoring server), and poll resources on three remote clusters on the same domain. 2 of the clusters are also running Windows Server 2008 R2, but one is running Windows Server 2012 (x64). The returned data will be inserted into a database as part of a monitoring app.

Currently the code I'm using is:

$clusters = "cluster1.domain.local","cluster2.domain.local","cluster3.domain.local"
foreach ( $cluster in $clusters) {
    $resources = Get-ClusterResource -Cluster $cluster | where-object {$_.ResourceType -match "Physical Disk"}
    foreach ( $resource in $resources) {
        $details = Get-ClusterResource -Cluster $cluster -Name $resource.Name | fc *
        <how to get disk size & space from $details?>
    }
}

The data returned by "Get-ClusterResource | fc *" doesn't include the physical disk size or free space, and I cannot work out how to derive this information. The returned information is generic to all Cluster Resources - an example can be seen here (Example 2). Example 3 below was almost helpful, but does not include disk size or free space.

I have checked this question but the answer uses WMI queries, and when I try this I run into all sorts of security and compatibility issues. I'd prefer to stick to straightforwards PowerShell if possible, especially as the monitoring app is also using pure PowerShell to check Exchange Mailbox sizes & DFS Replication Backlogs.

Please note I am not trying to query Cluster Shared Volumes - they have their own, separate PowerShell functions and I've got this working no problems. It's specifically for Physical Disk Resources that I can't get it to work.

I understand that Physical Disks are one of many Resource types, and so the generic Get-ClusterResource command will not return anything disk specific, but I was hoping for another function I could call, passing in the return value of Get-ClusterResource, to retrieve the disk space/free space

Any assistance would be appreciated, thanks

Sam


Updates for Ansgar Wiechers

  • What is your objective? As already specified, to create a series of 'data collector' powershell scripts that gather data from multiple systems that need monitoring, and inject this data into a database that will provide alerts, retain history and generally enhance our monitoring abilities. Our current suite of monitoring tools covers 90% of what we need, but just misses on a few little things, which I am hoping to rectify using this method

  • Why do you need physical disk parameters instead of CSV parameters? Because CSVs aren't the only type of disk used in a cluster. As an example, we have a 2 server, 7-instance, 31-volume SQL cluster. It is IMPERATIVE that the free disk space on all volumes is monitored, for reasons which I would assume to be obvious. This monitoring is currently done manually, and lacks historical retention

  • Of which physical disks? Whichever ones I specify. An ideal solution would be able to monitor any in-use (ie not 'Available') cluster disk resource. I do not intend to monitor 'useless' disks such as the DTC volume on our SQL cluster, or the Quorum volumes, but there's no reason I should not be ABLE to monitor these, if I choose to

  • And why do you want to get this information through the cluster instead of monitoring physical disk information on the cluster members Whilst it is possible to get some of this information via SNMP MIBs, the information is much more difficult to obtain, interpret and translate. I can go into detail on this, but it would detract focus from the question, suffice it to say Powershell is my preferred method

Answer

Ansgar Wiechers picture Ansgar Wiechers · Jul 26, 2013

You can't obtain free space information on a physical disk level. That kind of information is only available on the filesystem/volume level. For monitoring purposes I'd simply do a

$filter = 'DriveType=3 AND DriveLetter IS NOT NULL'

gwmi Win32_Volume -Filter $filter | select DriveLetter, Capacity, FreeSpace

on each cluster node. That will give you the size and free space of "regular" volumes. You can run remote WMI queries by passing an array of hostnames to the -Computer option. In that case I'd recommend including the SystemName property with the output:

$filter = 'DriveType=3 AND DriveLetter IS NOT NULL'
$nodes  = Get-ClusterNode -Cluster $cluster `
            | ? { $_.State -eq 'up' } `
            | % { $_.Name }

gwmi Win32_Volume -Computer $nodes -Filter $filter |
    select SystemName, DriveLetter, Capacity, FreeSpace

CSVs can't be monitored like that, so their data must be obtained like this:

Get-ClusterSharedVolume -Cluster $cluster `
  | select -Expand SharedVolumeInfo `
  | select FriendlyVolumeName, @{n="Capacity";e={$_.Partition.Size}},
      @{n="FreeSpace";e={$_.Partition.Size - $_.Partition.UsedSpace}}

And I'd appreciate it if you used a less condescending tone when answering my questions. It's not like I have to solve your problems.