Displaying Logical Drives with PowerShell

PowerShell is a powerful scripting language and can do many things. One task that can be used over and over is to get the logical drives off a system. One you have this information you can then perform tasks like searching for files, directories, reporting usage etc..

In this post I will be simply showing how to create a variable and retrieve the data for the logical drives using WMI object win32_logicaldisk.

If we just enter Get-WmiObject win32_logicaldisk we see the output showing Device ID, DriveType, ProviderName, FreeSpace, Size and VolumeName.

Now let’s take this a bit further and tell it we want DriveType 3. Which in this instance we see drive D: removed from the list, which is DriveType 5 (CD-ROM)

So what can we do next? Well, how about let’s create a list of just the drive name? No problem, let’s build on the command and add the foreach-object and grab the name.

Now we have something we can work with and can assign this to a variable that we can use in a script. Let’s take the line and add $drives = to the front of the command and create the $drives variable which we can reference.

Now lets go a step further and get the first level of the directory for the drive. We need to do a foreach and use the Get-ChildItem cmdlet.

So as you can see there are many other possibilities from what was touched on here. Have fun and keep PowerShelling !!!

8 Responses to “Displaying Logical Drives with PowerShell”

  1. Bill Moore says:

    This post was helpful to me today. For as simple as this is (?{$_.drivetype -eq 3} | foreach-object {$}) it was really causing me fits. I will using something similar on a post I am working on for my blog about offline domain joining pc’s and will be sure to credit you appropriately. Thanks for posting this. You are now a part of my feed list. 🙂


  2. venkat teki says:


    Does this query also lists the NFS shares exposed from this windows machine?

  3. ravi says:

    I am using the below function to get the drives disk information from the remote servers. I am unable to get the few disk information. Could you please help me to get it.

    $disks = Get-WmiObject -Class Win32_LogicalDisk -ComputerName $computer -Filter “DriveType = 3”


  1. Djoin, PowerShell, and Standalone Media | - […] shoutout to newlife007 over at LifeOfAGeekAdmin for a great little read on using PowerShell for displaying logical drives that inspired me to […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.