PowerTip: List Physical Drives with PowerShell

Summary: Use Windows PowerShell to list physical drives.

Hey, Scripting Guy! Question How can I use Windows PowerShell to get a list of physical drives?

Hey, Scripting Guy! Answer Use Get-WMIObject, query win32_logicaldisk, and filter with the DriveType property:

GET-WMIOBJECT –query “SELECT * from win32_logicaldisk where DriveType = ‘3’”

To check the drives on a remote computer, add the –ComputerName parameter.
For example, to list all physical drives and their free space on a machine called “ContosoWS1”:

GET-WMIOBJECT –query “SELECT * from win32_logicaldisk where DriveType = ‘3’”
–computername “ContosoWS1”

Comments (14)

  1. @Christophe

    Actually it works that way in Windows 7 as well.  It's just a force of habit I have when working with WMI queries to isolate the results in the query.

    Love that you're rocking it with PowerShell!


  2. Anonymous says:

    I am trying to get a list which contains drives of multiple servers and I wrote a script. But it looks like it is not taking multiple computers.
    Script is below

    get-WmiObject win32_logicaldisk -ComputerName (get-content d:scriptssea.txt) | Format-table -Property @{name=’Free space(in GB)’; e={$_.Freespace/1GB}; align=’right’; formatstring=’N2′}, @{name=’Total Size (in GB)’; e={$_.size/1GB}; align=’right’; formatstring=’N2′} -autosize >>D:ScriptsTest.csv

    Please suggest alternatives.

  3. Boe Prox says:

    This is one of the preferred ways of filtering with Get-WMIObject using -Query:
    Get-WMIObject -Query "Select * FROM Win32_LogicalDisk WHERE DriveType=3"

    You could also use -Filter as well if desired:
    Get-WMIObject -Class Win32_logicaldisk -Filter "DriveType=’3’"

    This applies the filter on the computer that it is being run against prior to sending the data back to PowerShell rather than bringing everything back to then be filtered by PowerShell.

    Try both of these out to see the difference between filtering using a parameter and using Where-Object:

    [tag:Using] the Query Parameter to filter:
    Get-WMIObject -Query "Select * FROM Win32_LogicalDisk WHERE DriveType=3" | Where {
    Write-Verbose $_ -Verbose

    [tag:Piping] data into Where-Object to filter:
    Get-WMIObject -Class Win32_logicaldisk | Where {
    Write-Verbose $_ -Verbose
    $_.DriveType -eq 3

  4. David Wyatt says:

    Strictly speaking, this command doesn't list physical drives at all.  It lists logical drives located on whatever Windows considers to be a "Local Disk" (which, oddly enough, includes some external USB drives, even though you might think those should be categorized as Removable).

    There can be many Win32_LogicalDisk objects associated with a single physical disk, if you have multiple partitions or volumes on that disk.

  5. @David

    You are correct in that it accesses the logical drive letters.   If you wish to access the PhysicalDisks leverage the win32_diskdrive within WMI.  The advantage I find with LogicalDisk is the ability to get the drive letter.


    Good tip on working with WMI Queries 🙂


  6. Anonymous says:


  7. jrv says:

    Quote are always soptional aroung numeric and Booleans.





    Strings always require quotes.  This is also true in almost all programming systems including VBScript and PowerShell.

  8. christophe says:

    For me, on Windows 8 Enterprise, i don't need the ' around the drivetype.

    These commandlets are OK for me:

    GET-WMIOBJECT –query “SELECT * from win32_logicaldisk where DriveType = 3”

    GET-WMIOBJECT –query “SELECT * from win32_logicaldisk where DriveType = 3”

    –computername “ContosoWS1”

  9. pete says:

    Caution:  the snippet contains "smart" quotes so can't be literally copy-pasted.  You need to edit the apos and quot chars after ^C  ^V

  10. sgardi says:

    Hi, I hope you can help. I need a good way to show the mapping between a iscsi lun to disk
    If I run Get-iSCSISession | Get-Disk | where {$_.operationalstatus -eq “online”} | Ft -autosize -wrap, I can see the disk number but the name isn’t detailed.
    Number Friendly Name OperationalStatus Total Size Partition Style
    15 LEFTHAND iSCSIDisk Multi-Path Disk Device Online 123 GB MBR

    I need the “TargetNodeAddress : iqn.2003-10.com.lefthandnetworks:avalonprod:71724:on-dc01-av” with the Lun or disk ID

    Any help is awesome!

  11. random IT guy says:

    I can not recollect ever having working code from the scripting guys

  12. someOther IT guy says:

    @random IT guy: Totally agree. The example given should have been:

    Get-WmiObject -Class Win32_LogicalDisk | Where { $_.DriveType -eq 3 }

  13. Gary says:

    How do I view physical disk status predictive failure / failed

  14. Daniel says:

    I get error:
    Get-WmiObject : Invalid query
    At line:1 char:14
    + GET-WMIOBJECT <<<< -query "SELECT * from win32_logicaldisk where DriveType = `3’"
    + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Skip to main content