List all devices, partitions and volumes in Powershell

后端 未结 9 816
时光取名叫无心
时光取名叫无心 2021-01-30 19:53

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/\" wi

相关标签:
9条回答
  • 2021-01-30 20:49

    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)]"
    }
    
    0 讨论(0)
  • 2021-01-30 20:50

    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
    
    0 讨论(0)
  • 2021-01-30 20:52

    Run command:

    Get-PsDrive -PsProvider FileSystem
    

    For more info see:

    • PsDrive Documentation

    • PSProvider Documentation

    0 讨论(0)
提交回复
热议问题