List all devices, partitions and volumes in Powershell
Asked Answered
S

13

86

I have multiple volumes (as nearly everybody nowadays): on Windows they end up specified as C:, D: and so on. How do I list these all like on a Unix machine with "ls /mnt/" with Powershell?

Scowl answered 2/11, 2009 at 20:42 Comment(1)
get-psdrive will return this Name Provider Root CurrentLocation ---- -------- ---- --------------- A FileSystem A:Alias Alias C FileSystem C:\ scriptsHeadword
B
111

To get all of the file system drives, you can use the following command:

gdr -PSProvider 'FileSystem'

gdr is an alias for Get-PSDrive, which includes all of the "virtual drives" for the registry, etc.

Booklover answered 2/11, 2009 at 20:52 Comment(3)
This also include the CD ROM which I am not sure is desired in all use cases keep that in mind guys.Interlocutrix
or you could also use Get-WmiObject Win32_LogicalDiskOsteo
This also does not include mount points such as iSCSI disks.Sawn
O
50
Get-Volume

You will get: DriveLetter, FileSystemLabel, FileSystem, DriveType, HealthStatus, SizeRemaining and Size.

Obovate answered 24/10, 2013 at 20:22 Comment(6)
Get-Volume appears to be available only on Windows-Server 2012 and Windows-Server 2016.Mackay
Get-Volume worked for me running powershell 5.1. Perhaps they made this standard in recent years/recent updates. This answer should get more attention.Plessor
This is now the right answer. The answers using Get-PDDrive are for older versions of powershellBritska
If you want details, there is Get-Drive and Get-Partition, that can be piped for everything. Get-Drive | Get-PartitionLighten
Worked for me on Windows 11 Pro.Harry
Also worked for me in Windows 11. This is definitely the way to go.Andiron
I
15

On Windows Powershell:

Get-PSDrive 
[System.IO.DriveInfo]::getdrives()
wmic diskdrive
wmic volume

Also the utility dskwipe: http://smithii.com/dskwipe

dskwipe.exe -l
Immersionism answered 23/7, 2012 at 9:19 Comment(1)
To tag on, you can also include a flag from another answer -PSProvider:'FileSystem' to display only file systems.Cathouse
J
5

Firstly, on Unix you use mount, not ls /mnt: many things are not mounted in /mnt.

Anyhow, there's the mountvol DOS command, which continues to work in Powershell, and there's the Powershell-specific Get-PSDrive.

Jahnke answered 2/11, 2009 at 20:52 Comment(0)
D
5

Run command:

Get-PsDrive -PsProvider FileSystem

For more info see:

Deliadelian answered 19/8, 2019 at 10:27 Comment(0)
E
4

Though this isn't 'powershell' specific... you can easily list the drives and partitions using diskpart, list volume

PS C:\Dev> diskpart

Microsoft DiskPart version 6.1.7601
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: Box

DISKPART> list volume

Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
----------  ---  -----------  -----  ----------  -------  ---------  --------
Volume 0     D                       DVD-ROM         0 B  No Media
Volume 1         C = System   NTFS   Partition    100 MB  Healthy    System
Volume 2     G   C = Box      NTFS   Partition    244 GB  Healthy    Boot
Volume 3     H   D = Data     NTFS   Partition    687 GB  Healthy
Volume 4     E   System Rese  NTFS   Partition    100 MB  Healthy
Expulsion answered 9/6, 2014 at 20:56 Comment(1)
is it possible to get Volume ## using powershell? (For windows 7)Inaccessible
L
2

This is pretty old, but I found following worth noting:

PS N:\> (measure-command {Get-WmiObject -Class Win32_LogicalDisk|select -property deviceid|%{$_.deviceid}|out-host}).totalmilliseconds
...
928.7403
PS N:\> (measure-command {gdr -psprovider 'filesystem'|%{$_.name}|out-host}).totalmilliseconds
...
169.474

Without filtering properties, on my test system, 4319.4196ms to 1777.7237ms. Unless I need a PS-Drive object returned, I'll stick with WMI.

EDIT: I think we have a winner: PS N:> (measure-command {[System.IO.DriveInfo]::getdrives()|%{$_.name}|out-host}).to‌​talmilliseconds 110.9819

Lifelike answered 26/2, 2013 at 18:20 Comment(0)
P
2

To list drives:

fsutil fsinfo drives

Is also supported by CMD and requires no elevation nor extra 3rd-parties.

Pedestrian answered 9/5, 2023 at 12:11 Comment(0)
M
1

We have multiple volumes per drive (some are mounted on subdirectories on the drive). This code shows a list of the mount points and volume labels. Obviously you can also extract free space and so on:

gwmi win32_volume|where-object {$_.filesystem -match "ntfs"}|sort {$_.name} |foreach-object {
  echo "$(echo $_.name) [$(echo $_.label)]"
}
Marche answered 26/3, 2015 at 13:37 Comment(1)
For PWSH 7, that would be Get-CimInstance Win32_Volume instead.Indestructible
P
1

If the device is present, but not (yet) mounted, this helps:

Get-PnpDevice -PresentOnly -InstanceId SCSI*
Perspective answered 22/1, 2023 at 21:14 Comment(0)
S
0

You can use the following to find the "total" disk size on a drive as well.

Get-CimInstance -ComputerName yourhostname Win32_LogicalDisk |
  foreach-object {
    write " $($_.Caption) $('{0:N2}' -f ($_.Size/1gb)) GB total, $('{0:N2}' -f ($_.FreeSpace/1gb)) GB free "
}

Simulant answered 25/5, 2021 at 20:5 Comment(2)
this seems like a VERY minor variation of one of the previous Answers. what is the benefit to yours that is not in the other?Potbelly
This will work with PWSH 7 as the previous answer wont...Indestructible
B
0

Microsoft have a way of doing this as part of their az vm repair scripts (see: Repair a Windows VM by using the Azure Virtual Machine repair commands).

It is available under MIT license at: https://github.com/Azure/repair-script-library/blob/51e60cf70bba38316394089cee8e24a9b1f22e5f/src/windows/common/helpers/Get-Disk-Partitions.ps1

Beghard answered 18/8, 2021 at 4:17 Comment(0)
F
-2

You can also do it on the CLI with

net use
Fugazy answered 8/4, 2020 at 13:53 Comment(1)
net use will only display mounted network devices.Indestructible

© 2022 - 2024 — McMap. All rights reserved.