List all devices, partitions and volumes in Powershell

后端 未结 9 815
时光取名叫无心
时光取名叫无心 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:28

    You can also do it on the CLI with

    net use
    
    0 讨论(0)
  • 2021-01-30 20:33

    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

    0 讨论(0)
  • 2021-01-30 20:38
    Get-Volume
    

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

    0 讨论(0)
  • 2021-01-30 20:42

    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.

    0 讨论(0)
  • 2021-01-30 20:45

    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.

    0 讨论(0)
  • 2021-01-30 20:48

    On Windows Powershell:

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

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

    dskwipe.exe -l
    
    0 讨论(0)
提交回复
热议问题