列出 Powershell 中的所有设备、分区和卷
我有多个卷(就像现在几乎每个人一样):在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
要获取所有文件系统驱动器,您可以使用以下命令:
gdr
是Get-PSDrive
,其中包括注册表等的所有“虚拟驱动器”。To get all of the file system drives, you can use the following command:
gdr
is an alias forGet-PSDrive
, which includes all of the "virtual drives" for the registry, etc.您将得到:
DriveLetter、FileSystemLabel、FileSystem、DriveType、HealthStatus、SizeRemaining 和 Size。
You will get:
DriveLetter, FileSystemLabel, FileSystem, DriveType, HealthStatus, SizeRemaining and Size.
在 Windows Powershell 上:
还有实用程序 dskwipe:http://smithii.com/dskwipe
On Windows Powershell:
Also the utility dskwipe: http://smithii.com/dskwipe
首先,在 Unix 上,您使用
mount
,而不是ls /mnt
:很多东西都没有安装在/mnt
中。无论如何,有
mountvol
DOS 命令,它继续在 Powershell 中工作,还有 Powershell 特定的Get-PSDrive
。Firstly, on Unix you use
mount
, notls /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-specificGet-PSDrive
.运行命令:
有关详细信息,请参阅:
PsDrive 文档
PSProvider 文档
Run command:
For more info see:
PsDrive Documentation
PSProvider Documentation
虽然这不是特定于“powershell”的...您可以使用 diskpart、list volume 轻松列出驱动器和分区
Though this isn't 'powershell' specific... you can easily list the drives and partitions using diskpart, list volume
这是相当古老的,但我发现以下值得注意:
没有过滤属性,在我的测试系统上,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:
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}).totalmilliseconds
110.9819
列出驱动器:
CMD 也支持,无需提升或额外的第三方。
To list drives:
Is also supported by CMD and requires no elevation nor extra 3rd-parties.
每个驱动器有多个卷(有些卷安装在驱动器上的子目录上)。此代码显示安装点和卷标签的列表。显然你还可以提取可用空间等等:
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:
如果设备存在,但尚未安装,这会有所帮助:
If the device is present, but not (yet) mounted, this helps:
Microsoft 有一种方法可以将其作为其
az vm Repair
脚本的一部分(请参阅:使用 Azure 虚拟机修复命令修复 Windows VM)。它可以在 MIT 许可证下获得:https://github.com/Azure/repair-script-library/blob/51e60cf70bba38316394089cee8e24a9b1f22e5f/src/windows/common/helpers/Get-Disk-Partitions.ps1
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
您也可以使用以下命令来查找驱动器上的“总”磁盘大小。
You can use the following to find the "total" disk size on a drive as well.
您还可以在 CLI 上执行此操作
You can also do it on the CLI with