windows batch wmic diskdrive get size where media type = 固定硬盘介质
windows batch wmic diskdrive get size where media type = Fixed hard disk media
我需要通过windows批处理文件获取本地安装的硬盘disk/disks大小,请帮助
for /f ? %%f in ('wmic diskdrive where (MediaType='Fixed hard disk media') get size /value') do echo "%%f"
您可能想要这样的东西:
@Echo Off
For /F "Skip=1 Delims=" %%A In (
'"WMIC LogicalDisk Where (DriveType='3') Get DeviceID, Size"'
) Do For /F "Tokens=1-2" %%B In ("%%A") Do Echo(%%B - %%C
Timeout -1
由于 LogicalDisk 将 return 仅分区大小,而现代驱动器的容量将超过 cmd.exe 的 set /A 命令的 32 位有符号整数数学,我建议使用 PowerShell 脚本来获取一些数据:
$Drives=0 ; $TotalSize=0
get-physicaldisk |
ForEach {$_;$Drives+=1;$TotalSize+=$_.Size}|
Format-Table -auto DeviceID,Size,BusType,MediaType,model,serialnumber
"Drives TotalSize"
"------- --------------"
"{0,-6} {1,15}" -f $Drives,$TotalSize
示例输出:
> .\SO_42525626.ps1
DeviceID Size BusType MediaType model serialnumber
-------- ---- ------- --------- ----- ------------
1 256060514304 SATA SSD Samsung SSD 840 PRO Series xxxxxxxxxxxxxxx
0 2000398934016 SATA HDD ST2000DL003-9VT166 yyyyyyyy
3 1000204886016 USB Unspecified 2105 zzzzzzzzzzzzzzzzzzzz
Drives TotalSize
------- --------------
3 3256664334336
我需要通过windows批处理文件获取本地安装的硬盘disk/disks大小,请帮助
for /f ? %%f in ('wmic diskdrive where (MediaType='Fixed hard disk media') get size /value') do echo "%%f"
您可能想要这样的东西:
@Echo Off
For /F "Skip=1 Delims=" %%A In (
'"WMIC LogicalDisk Where (DriveType='3') Get DeviceID, Size"'
) Do For /F "Tokens=1-2" %%B In ("%%A") Do Echo(%%B - %%C
Timeout -1
由于 LogicalDisk 将 return 仅分区大小,而现代驱动器的容量将超过 cmd.exe 的 set /A 命令的 32 位有符号整数数学,我建议使用 PowerShell 脚本来获取一些数据:
$Drives=0 ; $TotalSize=0
get-physicaldisk |
ForEach {$_;$Drives+=1;$TotalSize+=$_.Size}|
Format-Table -auto DeviceID,Size,BusType,MediaType,model,serialnumber
"Drives TotalSize"
"------- --------------"
"{0,-6} {1,15}" -f $Drives,$TotalSize
示例输出:
> .\SO_42525626.ps1
DeviceID Size BusType MediaType model serialnumber
-------- ---- ------- --------- ----- ------------
1 256060514304 SATA SSD Samsung SSD 840 PRO Series xxxxxxxxxxxxxxx
0 2000398934016 SATA HDD ST2000DL003-9VT166 yyyyyyyy
3 1000204886016 USB Unspecified 2105 zzzzzzzzzzzzzzzzzzzz
Drives TotalSize
------- --------------
3 3256664334336