Appearance
磁盘管理
磁盘信息
wmic 磁盘信息
cmd
wmic diskdrive get model,size,status
wmic diskdrive get model,size,interfacetype
wmic diskdrive list brief
wmic diskdrive list full
wmic logicaldisk get caption,volumename,size,freespace
wmic logicaldisk where "drivetype=3" get caption,size,freespace
wmic volume get driveletter,capacity,freespace,filesystemfsutil 磁盘信息
cmd
fsutil volume diskfree C: # 磁盘空间
fsutil volume list # 列出卷
fsutil fsinfo volumeinfo C: # 卷信息
fsutil fsinfo ntfsinfo C: # NTFS 信息
fsutil fsinfo drives # 列出驱动器
fsutil fsinfo drivetype C: # 驱动器类型PowerShell 磁盘信息
powershell
Get-PhysicalDisk # 物理磁盘
Get-Disk # 磁盘信息
Get-Volume # 卷信息
Get-Partition # 分区信息
Get-Volume | Format-Table DriveLetter, FileSystemLabel, SizeRemaining, Size
Get-PhysicalDisk | Select-Object FriendlyName, MediaType, Size磁盘分区
diskpart - 磁盘分区工具
cmd
diskpart # 进入 diskpartdiskpart 命令:
list disk # 列出磁盘
list volume # 列出卷
list partition # 列出分区
select disk 0 # 选择磁盘
select volume 1 # 选择卷
select partition 1 # 选择分区
clean # 清除磁盘
create partition primary # 创建主分区
create partition primary size=50000 # 创建指定大小分区
create partition extended # 创建扩展分区
create partition logical # 创建逻辑分区
create partition efi size=100 # 创建 EFI 分区
format fs=ntfs quick # 快速格式化
format fs=ntfs label="Data" quick # 带卷标格式化
format fs=fat32 quick # FAT32 格式化
active # 设置活动分区
assign # 自动分配盘符
assign letter=D # 指定盘符
remove letter=D # 删除盘符
delete partition # 删除分区
delete partition override # 强制删除分区
extend # 扩展分区
extend size=10000 # 扩展指定大小
shrink desired=10000 # 缩小分区
detail disk # 磁盘详情
detail volume # 卷详情
detail partition # 分区详情
exit # 退出批处理分区脚本
cmd
echo list disk | diskpart
(echo select disk 0 & echo clean & echo create partition primary & echo format fs=ntfs quick & echo assign) | diskpartPowerShell 分区管理
powershell
Get-Disk | Initialize-Disk -PartitionStyle GPT
New-Partition -DiskNumber 0 -Size 100GB -DriveLetter D
Format-Volume -DriveLetter D -FileSystem NTFS -NewFileSystemLabel "Data"
Resize-Partition -DiskNumber 0 -PartitionNumber 1 -Size 200GB
Remove-Partition -DiskNumber 0 -PartitionNumber 1磁盘格式化
format - 格式化
cmd
format D: /fs:ntfs # NTFS 格式化
format D: /fs:ntfs /q # 快速格式化
format D: /fs:ntfs /v:Data # 设置卷标
format D: /fs:fat32 # FAT32 格式化
format D: /fs:exfat # exFAT 格式化
format D: /fs:ntfs /a:4096 # 指定簇大小
format D: /fs:ntfs /x # 强制卸载PowerShell 格式化
powershell
Format-Volume -DriveLetter D -FileSystem NTFS
Format-Volume -DriveLetter D -FileSystem NTFS -NewFileSystemLabel "Data"
Format-Volume -DriveLetter D -FileSystem NTFS -AllocationUnitSize 4096
Format-Volume -DriveLetter D -FileSystem FAT32
Format-Volume -DriveLetter D -FileSystem exFAT磁盘检查
chkdsk - 磁盘检查
cmd
chkdsk C: # 检查磁盘
chkdsk C: /f # 修复错误
chkdsk C: /r # 检查坏扇区
chkdsk C: /x # 强制卸载卷
chkdsk C: /f /r # 完整检查修复
chkdsk C: /b # 重新评估坏簇
chkdsk C: /scan # 联机扫描
chkdsk C: /perf # 使用更多资源fsutil 检查
cmd
fsutil dirty query C: # 查询脏标志
fsutil dirty set C: # 设置脏标志磁盘清理
cleanmgr - 磁盘清理
cmd
cleanmgr # 打开磁盘清理
cleanmgr /sageset:1 # 设置清理选项
cleanmgr /sagerun:1 # 执行清理
cleanmgr /d C # 指定驱动器手动清理
cmd
del /q /s C:\Windows\Temp\*
del /q /s %TEMP%\*
del /q /s C:\Windows\SoftwareDistribution\Download\*
dism /online /cleanup-image /startcomponentcleanup
dism /online /cleanup-image /startcomponentcleanup /resetbase磁盘碎片整理
defrag - 碎片整理
cmd
defrag C: # 整理碎片
defrag C: /a # 分析
defrag C: /o # 优化
defrag C: /x # 合并碎片
defrag C: /u # 显示进度
defrag C: /v # 详细输出
defrag /c # 整理所有卷
defrag /c /h # 高优先级整理所有卷PowerShell 碎片整理
powershell
Optimize-Volume -DriveLetter C -Defrag
Optimize-Volume -DriveLetter C -Analyze
Optimize-Volume -DriveLetter C -Trim
Optimize-Volume -DriveLetter C -SlabConsolidate磁盘配额
fsutil 配额管理
cmd
fsutil quota query C: # 查询配额
fsutil quota enforce C: # 启用配额
fsutil quota disable C: # 禁用配额
fsutil quota track C: # 跟踪配额
fsutil quota modify C: 1000000000 2000000000 usernamePowerShell 配额管理
powershell
Get-FsrmQuota
New-FsrmQuota -Path "C:\Users" -Size 10GB
Set-FsrmQuota -Path "C:\Users" -Size 20GB
Remove-FsrmQuota -Path "C:\Users"VHD 虚拟磁盘
diskpart VHD 操作
create vdisk file="C:\disk.vhd" maximum=10000 type=expandable
create vdisk file="C:\disk.vhd" maximum=10000 type=fixed
select vdisk file="C:\disk.vhd"
attach vdisk
detach vdisk
compact vdisk
expand vdisk maximum=20000
merge vdisk depth=1PowerShell VHD 操作
powershell
New-VHD -Path "C:\disk.vhd" -SizeBytes 10GB -Dynamic
New-VHD -Path "C:\disk.vhd" -SizeBytes 10GB -Fixed
Mount-VHD -Path "C:\disk.vhd"
Dismount-VHD -Path "C:\disk.vhd"
Optimize-VHD -Path "C:\disk.vhd"
Resize-VHD -Path "C:\disk.vhd" -SizeBytes 20GB
Get-VHD -Path "C:\disk.vhd"存储空间
PowerShell 存储空间管理
powershell
Get-StoragePool
New-StoragePool -FriendlyName "Pool1" -StorageSubsystemFriendlyName "Windows Storage*" -PhysicalDisks (Get-PhysicalDisk)
New-VirtualDisk -StoragePoolFriendlyName "Pool1" -FriendlyName "VDisk1" -Size 100GB
Get-VirtualDisk
Remove-VirtualDisk -FriendlyName "VDisk1"磁盘性能
wmic 性能监控
cmd
wmic diskdrive get status
wmic logicaldisk get caption,size,freespacePowerShell 性能监控
powershell
Get-Counter '\PhysicalDisk(*)\Disk Reads/sec'
Get-Counter '\PhysicalDisk(*)\Disk Writes/sec'
Get-Counter '\PhysicalDisk(*)\Avg. Disk sec/Read'
Get-Counter '\PhysicalDisk(*)\Avg. Disk sec/Write'
Get-Counter '\PhysicalDisk(*)\% Disk Time'typeperf 性能监控
cmd
typeperf "\PhysicalDisk(_Total)\Disk Reads/sec"
typeperf "\PhysicalDisk(_Total)\Disk Writes/sec"
typeperf "\PhysicalDisk(_Total)\% Disk Time"
typeperf "\PhysicalDisk(_Total)\Avg. Disk Queue Length"磁盘健康
wmic 磁盘状态
cmd
wmic diskdrive get status
wmic diskdrive get model,statusPowerShell 磁盘健康
powershell
Get-PhysicalDisk | Select-Object FriendlyName, MediaType, HealthStatus, OperationalStatus
Get-StorageReliabilityCounter
Get-PhysicalDisk | Get-StorageReliabilityCounter | Select-Object DeviceId, Temperature, ReadErrorsTotal, WriteErrorsTotal磁盘映射
subst - 虚拟驱动器
cmd
subst X: C:\Users\Documents # 映射目录到驱动器
subst # 列出映射
subst X: /d # 删除映射mountvol - 挂载卷
cmd
mountvol # 列出挂载点
mountvol C:\Mount \\?\Volume{guid}\
mountvol C:\Mount /d # 删除挂载点磁盘备份
wbadmin - Windows 备份
cmd
wbadmin start backup -backupTarget:D: -include:C: -allCritical -quiet
wbadmin start backup -backupTarget:\\server\share -include:C:,D: -quiet
wbadmin get versions # 列出备份版本
wbadmin get status # 查看备份状态
wbadmin start recovery -version:version -items:C: -itemtype:Volume
wbadmin delete backup -keepVersions:5PowerShell 备份
powershell
Start-WBBackup -BackupTarget "D:"
Get-WBBackupSet
Start-WBRecovery -BackupSet (Get-WBBackupSet)[0]磁盘加密
manage-bde - BitLocker
cmd
manage-bde -status # 查看状态
manage-bde -on C: # 启用 BitLocker
manage-bde -off C: # 禁用 BitLocker
manage-bde -pause C: # 暂停加密
manage-bde -resume C: # 恢复加密
manage-bde -protectors -add C: -password
manage-bde -protectors -add C: -recoverykey E:
manage-bde -protectors -get C: # 获取保护器
manage-bde -unlock D: -recoverykey E:\key.bek
manage-bde -changepassword C:PowerShell BitLocker
powershell
Enable-BitLocker -MountPoint "C:" -EncryptionMethod XtsAes256
Enable-BitLocker -MountPoint "C:" -UsedSpaceOnly -RecoveryPasswordProtector
Disable-BitLocker -MountPoint "C:"
Suspend-BitLocker -MountPoint "C:"
Resume-BitLocker -MountPoint "C:"
Get-BitLockerVolume
Backup-BitLockerKeyProtector -MountPoint "C:" -KeyProtectorId "ID"