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

发布于 2024-08-09 22:38:15 字数 104 浏览 3 评论 0原文

我有多个卷(就像现在几乎每个人一样):在 Windows 上,它们最终被指定为 C:、D: 等。我如何像在 Unix 机器上一样使用 Powershell 使用“ls /mnt/”列出这些内容?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

╰つ倒转 2024-08-16 22:38:15

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

gdr -PSProvider 'FileSystem'

gdrGet-PSDrive,其中包括注册表等的所有“虚拟驱动器”。

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.

美男兮 2024-08-16 22:38:15
Get-Volume

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

Get-Volume

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

愛放△進行李 2024-08-16 22:38:15

在 Windows Powershell 上:

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

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

dskwipe.exe -l

On Windows Powershell:

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

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

dskwipe.exe -l
暗藏城府 2024-08-16 22:38:15

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

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

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.

情仇皆在手 2024-08-16 22:38:15

运行命令:

Get-PsDrive -PsProvider FileSystem

有关详细信息,请参阅:

Run command:

Get-PsDrive -PsProvider FileSystem

For more info see:

远山浅 2024-08-16 22:38:15

虽然这不是特定于“powershell”的...您可以使用 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

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
怼怹恏 2024-08-16 22:38:15

这是相当古老的,但我发现以下值得注意:

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

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

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

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

你如我软肋 2024-08-16 22:38:15

列出驱动器:

fsutil fsinfo drives

CMD 也支持,无需提升或额外的第三方。

To list drives:

fsutil fsinfo drives

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

掩耳倾听 2024-08-16 22:38:15

每个驱动器有多个卷(有些卷安装在驱动器上的子目录上)。此代码显示安装点和卷标签的列表。显然你还可以提取可用空间等等:

gwmi win32_volume|where-object {$_.filesystem -match "ntfs"}|sort {$_.name} |foreach-object {
  echo "$(echo $_.name) [$(echo $_.label)]"
}

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)]"
}
荒人说梦 2024-08-16 22:38:15

如果设备存在,但尚未安装,这会有所帮助:

Get-PnpDevice -PresentOnly -InstanceId SCSI*

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

Get-PnpDevice -PresentOnly -InstanceId SCSI*
め可乐爱微笑 2024-08-16 22:38:15

您也可以使用以下命令来查找驱动器上的“总”磁盘大小。

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

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

怕倦 2024-08-16 22:38:15

您还可以在 CLI 上执行此操作

net use

You can also do it on the CLI with

net use
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文