list 列出 Powershell 中的所有设备、分区和卷

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1663565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 01:24:55  来源:igfitidea点击:

List all devices, partitions and volumes in Powershell

listpowershelldevice

提问by wishi

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?

我有多个卷(现在几乎每个人都如此):在 Windows 上,它们最终被指定为 C:、D: 等等。如何在带有 "ls /mnt/" 和 Powershell 的 Unix 机器上列出所有这些?

回答by bdukes

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

要获取所有文件系统驱动器,您可以使用以下命令:

gdr -PSProvider 'FileSystem'

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

gdr是 的别名Get-PSDrive,其中包括注册表等的所有“虚拟驱动器”。

回答by Vladimir Valchev

Get-Volume

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

您将获得:DriveLetter、FileSystemLabel、FileSystem、DriveType、HealthStatus、SizeRemaining 和 Size。

回答by Vladimir Valchev

On Windows Powershell:

在 Windows PowerShell 上:

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

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

还有实用程序 dskwipe:http://smithii.com/dskwipe

dskwipe.exe -l

回答by ephemient

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

首先,在您使用的 Unix 上mount,不是ls /mnt:很多东西都没有安装在/mnt.

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

无论如何,有mountvolDOS 命令,它继续在 Powershell 中工作,还有特定于 Powershell 的Get-PSDrive.

回答by Yevgeniy

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.

没有过滤属性,在我的测试系统上,4319.4196ms 到 1777.7237ms。除非我需要返回一个 PS-Drive 对象,否则我会坚持使用 WMI。

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

编辑:我认为我们有一个赢家:PS N:> (measure-command {[System.IO.DriveInfo]::getdrives()|%{$_.name}|out-host}).to??talmilliseconds 110.9819

回答by Eddie B

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

虽然这不是“powershell”特定的......您可以使用diskpart轻松列出驱动器和分区,列出卷

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

回答by Patrick

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)]"
}

回答by Mwiza

Run command:

运行命令:

Get-PsDrive -PsProvider FileSystem

For more info see:

有关更多信息,请参阅:

回答by M46

You can also do it on the CLI with

您也可以在 CLI 上使用

net use