PowerShell for Failover Clustering: Finding the Drive Letter

PowerShell for Failover Clustering: Finding the Drive Letter

Rate This
  • Comments 3

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:\Windows\system32> $Partition | select Path

Path

----

J:

Q:

 

Enjoy!

Ahmed Bisht

Senior Program Manager

Clustering & High-Availability

Microsoft

Leave a Comment
  • Please add 3 and 6 and type the answer here:
  • Post
  • Works well for my Win 2008 Failover Clustering Environment. Any suggestions how to do that with MSCS 2003 ? Some WMI Classes used here don´t exist in Microosoft Cluster 2003

  • Hi Klaus,

    You are correct - although PowerShell will often work down-level at least one version, unfortunately the WMI Disk class that this PowerShell script was introduced in Windows 2008.

    -Rob.

  • would be very nice to have an example how to change or set a drive letter in Windows Server 2008 R2 (or later) using powershell only.

Page 1 of 1 (3 items)