Use PowerShell to find out if a Disk Partition is GPT or MBR

When you go to create a partition on a disk in Windows, you can use two different styles, MBR and GPT. The stand for Master Boot Record and Guid Partition Table. One of the major differences between these two is the size of partition you can create. If you have SAN storage and are using CSV’s in Hyper-V, you very well might bump up against this. MBR partitions are limited to 2 Terabytes (2.19 * 1012). GPT allows for a maximum size of 9.4 ZettaBytes (9.4 x 1021) In other words, at this point size doesn’t matter, at least in this decade.

Anyway, I had a situation where I needed to use diskpart.exe to reset a disk signature. The problem was, disk signatures are GUID’s for GPT disks and a set of hex digits for MBR’s. I needed to figure out how to code this and do the appropriate task in DiskPart. I ended up using WMI to figure it out

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027

Function Get-DiskPartitionStyle {

param

(
[Parameter( ValueFromPipeline=$true,
ValueFromPipelineByPropertyName = $true)]
$Disks="*"
,

[
Parameter( ValueFromPipeline=$true,
ValueFromPipelineByPropertyName = $true)]
$Computer ="."
)

PROCESS
{

$partitions = Get-WmiObject Win32_DiskPartition -computer $Computer

foreach ($disk in $Disks) {
    $partitions | Select @{name="DiskID" ;e={$_.DiskIndex}},Type,Name |
    Where-Object {$_.DiskID -like $disk}
        }
    }
}


Get-DiskPartitionStyle
Get-DiskPartitionStyle
-disks 10
Get-DiskPartitionStyle -disks 0,5,7,10

I used PowerShell to create an Advanced Function. By Default, it will return all partitions and their disks. You can also specify just the disk you want as well an array of disks.

Comments are closed