PowerShell for Failover Clustering: Finding the Drive Letter

Published Mar 15 2019 01:50 PM 536 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


%3CLINGO-SUB%20id%3D%22lingo-sub-371533%22%20slang%3D%22en-US%22%3EPowerShell%20for%20Failover%20Clustering%3A%20Finding%20the%20Drive%20Letter%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-371533%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Oct%2016%2C%202009%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EHi%20cluster%20scripting%20fans%2C%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EI%20often%20find%20myself%20looking%20for%20the%20drive%20letter(s)%20for%20a%20physical%20disk%20resource%20in%20a%20PowerShell%20console%2Fscript.%20%26nbsp%3BAfter%20a%20bit%20of%20investigation%2C%20here%20is%20a%20way%20to%20do%20that%20using%20Cluster%20WMI%20through%20PowerShell%3A%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%24DiskResourceName%20%3D%20%22Cluster%20Disk%202%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%24DiskResource%20%3D%20gwmi%20MSCluster_Resource%20-Namespace%20root%2Fmscluster%20%7C%20%3F%7B%20%24_.Name%20-eq%20%24DiskResourceName%20%7D%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%24Disk%20%3D%20gwmi%20-Namespace%20root%2Fmscluster%20-Query%20%22Associators%20of%20%7B%24DiskResource%7D%20Where%20ResultClass%3DMSCluster_Disk%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%24Partition%20%3D%20gwmi%20-Namespace%20root%2Fmscluster%20-Query%20%22Associators%20of%20%7B%24Disk%7D%20Where%20ResultClass%3DMSCluster_DiskPartition%22%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EAfter%20you%20run%20those%20CMDlets%20in%20your%20PowerShell%20window%20on%20a%20cluster%20node%2C%20the%20%24Partition%20variable%20will%20contain%20a%20MSCluster_DiskPartition%20WMI%20object%20per%20volume%20on%20the%20physical%20disk%20resource%20you%20specified%20with%20%24DiskResourceName.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EHere%20is%20an%20example%20when%20I%20run%20this%20against%20a%20physical%20disk%20resource%20with%20one%20partition%3A%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%24Partition%20%7C%20select%20Path%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EPath%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E----%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EL%3A%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%E2%80%A6%20and%20here%20with%20two%20partitions%3A%3C%2FP%3E%0A%20%20%3CP%3EPS%20G%3AWindowssystem32%26gt%3B%20%24Partition%20%7C%20select%20Path%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EPath%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E----%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EJ%3A%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EQ%3A%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EEnjoy!%3C%2FP%3E%0A%20%20%3CP%3EAhmed%20Bisht%3C%2FP%3E%0A%20%20%3CP%3ESenior%20Program%20Manager%3C%2FP%3E%0A%20%20%3CP%3EClustering%20%26amp%3B%20High-Availability%3C%2FP%3E%0A%20%20%3CP%3EMicrosoft%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-371533%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Oct%2016%2C%202009%20Hi%20cluster%20scripting%20fans%2C%26nbsp%3BI%20often%20find%20myself%20looking%20for%20the%20drive%20letter(s)%20for%20a%20physical%20disk%20resource%20in%20a%20PowerShell%20console%2Fscript.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-371533%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Efailover%20clustering%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EStorage%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Mar 15 2019 01:50 PM
Updated by: