如果我发射磁盘管理控制台,我最终获得了有关我的分区的完整信息,包括大小和当前文件系统(ntfs,fat32等...)
这里有我规划 Linux Mint 多重启动所需的所有信息。但我更希望以文本形式获取这些信息,因为我无法在安装 Linux 时运行磁盘管理器。
问:我可以用什么来列出每个分区正在使用的文件系统以及大小?
diskpart list volume
看起来它可以起到作用,但在 Windows 10 中找不到。
get-partition
给出了尺寸,但没有告诉我其他信息:
DiskPath: \\?\scsi#disk&ven_&prod_liteonit_lcs-256#4&2bcd8382&0&040000#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}
PartitionNumber DriveLetter Offset Size Type
--------------- ----------- ------ ---- ----
1 1048576 450 MB Recovery
2 472907776 100 MB System
3 577765376 16 MB Reserved
4 C 594542592 95.5 GB Basic
5 103135838208 450 MB Recovery
6 H 103607697408 107.32 GB Basic
7 I 218846199808 14.65 GB Basic
8 234574839808 20.01 GB Recovery
DiskPath: \\?\scsi#disk&ven_&prod_st1000lm024_hn-m#4&2bcd8382&0&000000#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}
PartitionNumber DriveLetter Offset Size Type
--------------- ----------- ------ ---- ----
1 D 1048576 465.75 GB Basic
2 E 500101545984 301.69 GB Basic
3 F 878569324544 15.62 GB Basic
4 G 895346540544 97.66 GB Basic
DiskPath:
\\?\usbstor#disk&ven_lexar&prod_usb_flash_drive&rev_1100#j8xx88thzzmnl0erdivy&0#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}
PartitionNumber DriveLetter Offset Size Type
--------------- ----------- ------ ---- ----
1 J 1048576 7.47 GB Basic
获取音量看起来很有希望,除了它没有告诉我未格式化分区的大小:
DriveLetter FileSystemLabel FileSystem DriveType HealthStatus OperationalStatus SizeRemaining Size
----------- --------------- ---------- --------- ------------ ----------------- ------------- ----
I Fixed Healthy Unknown 0 B 0 B
Restore NTFS Fixed Healthy OK 7.2 GB 20.01 GB
Recovery NTFS Fixed Healthy OK 76.66 MB 450 MB
K CD-ROM Healthy Unknown 0 B 0 B
C NTFS Fixed Healthy OK 59.37 GB 95.5 GB
J LINUX MINT FAT32 Removable Healthy OK 5.56 GB 7.45 GB
NTFS Fixed Healthy OK 146.66 MB 450 MB
H DATA NTFS Fixed Healthy OK 107.03 GB 107.32 GB
E Data2 NTFS Fixed Healthy OK 142.64 GB 301.69 GB
D Data1 NTFS Fixed Healthy OK 93.58 GB 465.75 GB
F Fixed Healthy Unknown 0 B 0 B
G Fixed Healthy Unknown 0 B 0 B
答案1
以下代码片段将列出所有卷的所有属性,以及每个特定卷以及相应的分区:
Get-Volume | ForEach-Object {
$VolObj = $_
$ParObj = Get-Partition | Where-Object { $_.AccessPaths -contains $VolObj.Path }
if ( $ParObj ) {
$VolObj | Select-Object -Property *
'------------'
$ParObj | Select-Object -Property *
'----------------------------------'
}
}
尝试将所需的属性组合到自定义对象中或简单地组合到标准输出中,例如
PS C:\Windows\system32> Get-Volume | ForEach-Object {
$VolObj = $_
$ParObj = Get-Partition | Where-Object { $_.AccessPaths -contains $VolObj.Path }
if ( $ParObj ) {
'{0,2} {1,2} {2,6} {3,20} {4,20} {5,2} {6}' -f $VolObj.DriveLetter,
$ParObj.DiskNumber,
$VolObj.FileSystem,
$VolObj.Size,
$VolObj.SizeRemaining,
$ParObj.PartitionNumber,
$VolObj.FileSystemLabel
}
}
D 0 NTFS 1000202039296 900793958400 1 DataDisk
1 NTFS 366997504 83173376 1 Rezervováno systémem
C 1 NTFS 119664537600 69979885568 2
答案2
JosefZ 的答案升级了:
$disksObject = @()
Get-WmiObject Win32_Volume -Filter "DriveType='3'" | ForEach-Object {
$VolObj = $_
$ParObj = Get-Partition | Where-Object { $_.AccessPaths -contains $VolObj.DeviceID }
if ( $ParObj ) {
$disksobject += [pscustomobject][ordered]@{
DiskID = $([string]$($ParObj.DiskNumber) + "-" + [string]$($ParObj.PartitionNumber)) -as [string]
Mountpoint = $VolObj.Name
Letter = $VolObj.DriveLetter
Label = $VolObj.Label
FileSystem = $VolObj.FileSystem
'Capacity(GB)' = ([Math]::Round(($VolObj.Capacity / 1GB),2))
'FreeSpace(GB)' = ([Math]::Round(($VolObj.FreeSpace / 1GB),2))
'Free(%)' = ([Math]::Round(((($VolObj.FreeSpace / 1GB)/($VolObj.Capacity / 1GB)) * 100),0))
}
}
}
$disksObject | Sort-Object DiskID | Format-Table -AutoSize
您可以根据自己的喜好使用 DriveTypes 修改驱动器过滤。目前它仅显示固定驱动器。
输出示例:
DiskID Mountpoint Letter Label FileSystem Capacity(GB) FreeSpace(GB) Free(%)
------ ---------- ------ ----- ---------- ------------ ------------- -------
0-1 C:\ C: Windows NTFS 80 38.18 48
1-1 E:\ E: DATA NTFS 30 25.52 85
2-1 E:\DATA\SQL\SY0\ SY0 NTFS 20 18.83 94
3-1 E:\DATA\SQL\SL0\ E:\DATA\SQL\SL0 NTFS 70 56.31 80
4-1 E:\DATA\SQL\ST0\ E:\DATA\SQL\ST0 NTFS 40 35.52 89
5-1 E:\DATA\SQL\SD0\ E:\DATA\SQL\SD0 NTFS 140 110.16 79
6-1 E:\DATA\SQL_Support\SS0\ E:\DATA\SQL_Support\SS0 NTFS 140 127.97 91