简体   繁体   English

如何使用 PowerShell 检测 MBR 磁盘上的未分配空间?

[英]How to use PowerShell to detect unallocated space on a MBR disk?

I am currently facing an issue with one of my MBR disks on a Windows server.我目前在 Windows 服务器上的一个 MBR 磁盘上遇到问题。 The disk is supposed to have a maximum size of 2048GB, but I have noticed that there is additional space allocated to it from the storage end.该磁盘的最大容量应该为 2048GB,但我注意到存储端为其分配了额外的空间。 After checking the disk, I found out that there is about 152GB of unallocated space on the disk.检查磁盘后,我发现磁盘上大约有 152GB 的未分配空间。

It is worth noting that if the allocated size was less than 2048GB, it would be easy to detect the unallocated space using the diskpart command.值得注意的是,如果分配的大小小于 2048GB,则使用 diskpart 命令很容易检测到未分配的空间。 However, in this case, the allocated size is more than the maximum size, which makes it difficult to detect the unallocated space.然而,在这种情况下,分配的大小大于最大大小,这使得检测未分配空间变得困难。

I have tried to detect this issue using various methods, such as the diskpart command, but I was unable to find any information about this unallocated space.我已尝试使用各种方法检测此问题,例如 diskpart 命令,但我无法找到有关此未分配空间的任何信息。 I also tried using the procmon tool and opening the diskmgmt snap-in, but the log was too huge and I couldn't find any useful information.我也尝试使用procmon工具并打开diskmgmt管理单元,但是日志太大,我找不到任何有用的信息。

I am now seeking help from the community to come up with a PowerShell script or command that can detect this unallocated space on the MBR disk.我现在正在寻求社区的帮助,想出一个 PowerShell 脚本或命令来检测 MBR 磁盘上的这个未分配空间。 I have been searching online but haven't found any solutions that work for me.我一直在网上搜索,但没有找到适合我的解决方案。 If anyone has any experience with this issue or know of a PowerShell script that can detect unallocated space on an MBR disk, please share it with me.如果有人对此问题有任何经验或知道可以检测 MBR 磁盘上未分配空间的 PowerShell 脚本,请与我分享。 I would greatly appreciate any help or guidance on this matter.对于此事,我将不胜感激任何帮助或指导。

I'm not sure how accurate this is, but you can try and count the total amount of allocated space and subtract that number from the total underlying disk size to get the maximum unallocated space:我不确定这有多准确,但您可以尝试计算已分配空间的总量,然后从基础磁盘总大小中减去该数字以获得最大未分配空间:

# Query the Win32_DiskDrive instance representing the physical disk
$disk = Get-CimInstance Win32_DiskDrive -Filter 'Index = 2'

# Find all associated partitions
$partitions = $disk |Get-CimAssociatedInstance -ResultClassName Win32_DiskPartition

# Calculate total allocation for configured partitions
$allocated = $partitions |Measure-Object -Sum Size |Select-Object -Expand Sum

# Calculate the remaining void
$unallocated = $disk.Size - $allocated

Write-Host ("There is {0}GB of disk space unallocated" -f $($unallocated/1GB))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM