PowerShell for Failover Clustering: Finding the Drive Letter
Published Mar 15 2019 01:50 PM 1,172 Views
Microsoft
First published on MSDN on Oct 16, 2009

Hi cluster scripting fans,

I often find myself looking for the drive letter(s) for a physical disk resource in a PowerShell console/script.  After a bit of investigation, here is a way to do that using Cluster WMI through PowerShell:

$DiskResourceName = "Cluster Disk 2"

$DiskResource = gwmi MSCluster_Resource -Namespace root/mscluster | ?{ $_.Name -eq $DiskResourceName }

$Disk = gwmi -Namespace root/mscluster -Query "Associators of {$DiskResource} Where ResultClass=MSCluster_Disk"

$Partition = gwmi -Namespace root/mscluster -Query "Associators of {$Disk} Where ResultClass=MSCluster_DiskPartition"

After you run those CMDlets in your PowerShell window on a cluster node, the $Partition variable will contain a MSCluster_DiskPartition WMI object per volume on the physical disk resource you specified with $DiskResourceName.

Here is an example when I run this against a physical disk resource with one partition:

$Partition | select Path

Path

----

L:

… and here with two partitions:

PS G:Windowssystem32> $Partition | select Path

Path

----

J:

Q:

Enjoy!

Ahmed Bisht

Senior Program Manager

Clustering & High-Availability

Microsoft


Version history
Last update:
‎Mar 15 2019 01:50 PM
Updated by: