Finding Drive Letters

by Aug 24, 2015

Here is a simple function to find out the reserved drive letters:

#requires -Version 3

function Get-DriveLetter
{
    (Get-WmiObject -Class Win32_LogicalDisk).DeviceID
}

To list all drive letters in use, try this:

 
PS> Get-DriveLetter
C:
D:
Y:
Z:

PS>
 

To find out whether a given drive letter is reserved, you could use it like this:

 
PS> $letters = Get-DriveLetter

PS> $letters -contains 'c:'
True

PS> $letters -contains 'f:'
False

PS>
 

Twitter This Tip! ReTweet this Tip!