2

I am currently facing an issue with one of my MBR disks on a Windows server. 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. After checking the disk, I found out that there is about 152GB of unallocated space on the disk.

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. 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. 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.

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. 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. I would greatly appreciate any help or guidance on this matter.

Fajela Tajkiya
  • 629
  • 2
  • 10
  • why do you use MBR on such a huge disk? In fact you should use GPT for almost all modern disks – phuclv Jan 26 '23 at 01:10

1 Answers1

1

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))
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • This seems like a good path to take, but it fails entirely on anything other than Index 2. Maybe you could do `Win32_DiskDrive -Filter 'MediaType = "Fixed hard disk media"'` instead to pick up fixed media (vs removable media). Might need to do a `ForEach` loop to go through disks and only get partitions per disk then. I suppose that depends on how detailed you want the report to be. Just a notice that there's unallocated space, or space per disk. – TheMadTechnician Jan 25 '23 at 19:26
  • 1
    @TheMadTechnician I didn't mean to imply you had to hardcode `-Filter 'Index = 2'`, I chose that because OP's screenshot indicates that would work for testing on the given machine :) – Mathias R. Jessen Jan 25 '23 at 19:28