我有多个卷(现在几乎每个人):在 Windows 上,它们最终指定为 C:、D: 等等。如何在带有 Powershell 的“ls /mnt/”的 Unix 机器上列出所有这些?
11 回答
Get-Volume
您将获得:DriveLetter、FileSystemLabel、FileSystem、DriveType、HealthStatus、SizeRemaining 和 Size。
在 Windows Powershell 上:
Get-PSDrive
[System.IO.DriveInfo]::getdrives()
wmic diskdrive
wmic volume
还有实用程序 dskwipe:http ://smithii.com/dskwipe
dskwipe.exe -l
首先,在 Unix 上你使用mount
,而不是ls /mnt
:很多东西都没有安装在/mnt
.
无论如何,有mountvol
DOS 命令,它继续在 Powershell 中工作,还有 Powershell 特定的Get-PSDrive
.
虽然这不是特定于“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
这已经很老了,但我发现以下值得注意:
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}).totalmilliseconds 110.9819
每个驱动器有多个卷(有些安装在驱动器的子目录中)。此代码显示了安装点和卷标的列表。显然你也可以提取空闲空间等等:
gwmi win32_volume|where-object {$_.filesystem -match "ntfs"}|sort {$_.name} |foreach-object {
echo "$(echo $_.name) [$(echo $_.label)]"
}
您也可以在 CLI 上使用
net use
您也可以使用以下内容来查找驱动器上的“总”磁盘大小。
Get-CimInstance -ComputerName yourhostname win32_logicaldisk | foreach-object {write " $($ .caption) $('{0:N2}' -f ($ .Size/1gb)) GB 总计,$('{0:N2}' -f ($_.FreeSpace /1gb)) GB 免费"}
Microsoft 有一种方法可以将其作为其az vm repair
脚本的一部分(请参阅:使用 Azure 虚拟机修复命令修复 Windows VM)。