Skip to main content

How to Get Disk Partition Style (MBR or GPT) in Batch Script

Before you can resize a partition, clone a drive, or deploy an operating system, you need to know whether the target disk uses the legacy MBR (Master Boot Record) or the modern GPT (GUID Partition Table) style. This distinction affects everything: the maximum disk size (MBR caps at 2 TB), the number of primary partitions (MBR allows 4, GPT allows 128), and the boot firmware compatibility (BIOS vs. UEFI). A Batch script can use PowerShell or DiskPart to identify the partition style of every disk in the system, providing the intelligence needed before any disk operation.

This guide will explain how to audit disk partition styles programmatically.

MBR vs. GPT: Why It Matters

FeatureMBRGPT
Maximum disk size2 TB18 exabytes (effectively unlimited)
Maximum partitions4 primary (or 3 primary + 1 extended)128
Boot firmwareBIOS onlyUEFI (required for modern Windows)
Data protectionSingle partition table, no redundancyBackup partition table at end of disk
Windows requirementWindows 7 BIOS boot, legacy systemsWindows 10/11 UEFI boot (recommended)

Rule of thumb: If the system uses UEFI firmware (virtually all machines from 2015 onwards), use GPT. Use MBR only for legacy BIOS compatibility.

Method 1: Comprehensive Disk and Partition Report

This method generates a detailed report of all disks showing their partition style, size, bus type, and health status.

@echo off
setlocal

echo [INFO] Disk partition style report:
echo --------------------------------------------------

powershell -NoProfile -Command ^
"$disks = Get-Disk -ErrorAction SilentlyContinue;" ^
"if (-not $disks) { Write-Host 'No disks found or access denied.'; exit 1 };" ^
"$disks | ForEach-Object {" ^
" $sizeGB = [math]::Round($_.Size / 1GB, 1);" ^
" [PSCustomObject]@{" ^
" 'Disk' = $_.Number;" ^
" 'Name' = $_.FriendlyName;" ^
" 'Size (GB)' = $sizeGB;" ^
" 'Style' = if ($_.PartitionStyle -eq 'RAW') { 'RAW (Uninitialized)' } else { [string]$_.PartitionStyle };" ^
" 'Bus' = [string]$_.BusType;" ^
" 'Health' = [string]$_.HealthStatus;" ^
" 'Boot' = $_.IsBoot" ^
" }" ^
"} | Format-Table -AutoSize"

echo --------------------------------------------------

endlocal
exit /b 0

Sample output:

Disk Name Size (GB) Style Bus Health Boot
---- ---- --------- ----- --- ------ ----
0 Samsung SSD 970 EVO Plus 476.9 GPT NVMe Healthy True
1 WDC WD40EFAX-68JH4N1 3726.0 GPT SATA Healthy False
2 Kingston DataTraveler 3.0 28.9 MBR USB Healthy False
3 Seagate Expansion 931.5 RAW (Uninitialized) USB Healthy False

What each column tells you:

  • Style: GPT, MBR, or RAW (Uninitialized). the critical information for planning disk operations.
  • Bus: How the disk is connected (NVMe, SATA, USB, SAS). USB disks may have compatibility issues with GPT conversion.
  • Boot: Whether this is the system boot disk. The boot disk's partition style must match the firmware type (GPT for UEFI, MBR for BIOS).
  • Health: Alerts you to failing hardware before you begin disk operations.

Method 2: Check a Specific Disk with Decision Logic

For automation pipelines (deployment scripts, disk preparation tools), this method checks a specific disk's partition style and makes decisions based on the result.

@echo off
setlocal EnableDelayedExpansion

set "TargetDisk=%~1"

if "%TargetDisk%"=="" (
echo Usage: %~nx0 ^<disk_number^>
echo.
echo Reports the partition style of a specific disk and provides guidance.
echo.
echo Example: %~nx0 1
echo.
echo Available disks:
powershell -NoProfile -Command "Get-Disk | Format-Table Number, FriendlyName, Size, PartitionStyle -AutoSize"
endlocal
exit /b 1
)

echo [INFO] Checking partition style of Disk %TargetDisk%...

:: Initialize variables
set "Style="
set "SizeGB="
set "DiskName="
set "PSResult=0"

:: Build PowerShell command
set "PSCmd=$disk = Get-Disk -Number %TargetDisk% -ErrorAction SilentlyContinue;"
set "PSCmd=!PSCmd! if (-not $disk) { Write-Output 'NOT_FOUND~~'; exit 2 };"
set "PSCmd=!PSCmd! $sizeGB = [math]::Round($disk.Size / 1GB, 1);"
set "PSCmd=!PSCmd! Write-Output ('{0}~{1}~{2}' -f $disk.PartitionStyle, $sizeGB, $disk.FriendlyName)"

:: Run PowerShell and capture output (using ~ as delimiter)
for /f "tokens=1-3 delims=~" %%a in (
'powershell -NoProfile -ExecutionPolicy Bypass -Command "!PSCmd!"'
) do (
set "Style=%%a"
set "SizeGB=%%b"
set "DiskName=%%c"
)

set "PSResult=!errorlevel!"

if "!Style!"=="NOT_FOUND" (
echo [ERROR] Disk %TargetDisk% does not exist. >&2
echo.
echo Available disks:
powershell -NoProfile -Command "Get-Disk | Format-Table Number, FriendlyName, Size, PartitionStyle -AutoSize"
endlocal
exit /b 1
)

if "!Style!"=="" (
echo [ERROR] Could not retrieve disk information. >&2
endlocal
exit /b 1
)

echo.
echo Disk: %TargetDisk% (!DiskName!)
echo Size: !SizeGB! GB
echo Style: !Style!
echo.

if /i "!Style!"=="GPT" (
echo [OK] Modern GPT layout.
echo - Supports disks larger than 2 TB
echo - Compatible with UEFI boot
echo - Up to 128 partitions
endlocal
exit /b 0
)

if /i "!Style!"=="MBR" (
echo [INFO] Legacy MBR layout.
echo - Maximum usable size: 2 TB
echo - Compatible with BIOS boot only
echo - Maximum 4 primary partitions

:: Check if MBR disk is larger than 2 TB
set "SizeCheck=0"
for /f %%s in ('powershell -NoProfile -Command "if (!SizeGB! -gt 2048) { Write-Output 1 } else { Write-Output 0 }"') do set "SizeCheck=%%s"

if "!SizeCheck!"=="1" (
echo.
echo [WARNING] This disk is larger than 2 TB but uses MBR.
echo Space beyond 2 TB is INACCESSIBLE.
echo Convert to GPT to use full capacity:
echo diskpart ^> select disk %TargetDisk% ^> convert gpt
)
endlocal
exit /b 0
)

if /i "!Style!"=="RAW" (
echo [INFO] Disk is RAW - not initialized.
echo - No partition table exists.
echo - Must be initialized with GPT or MBR before use.
echo.
echo Initialize with GPT (recommended^):
echo diskpart
echo select disk %TargetDisk%
echo convert gpt
echo.
echo Or with MBR (legacy^):
echo diskpart
echo select disk %TargetDisk%
echo convert mbr
endlocal
exit /b 0
)

:: Unknown style
echo [WARNING] Unknown partition style: !Style!
endlocal
exit /b 0

Why RAW detection is important:

A brand-new, uninitialized disk has a partition style of RAW. It is neither MBR nor GPT until explicitly initialized. Scripts that assume every disk is either MBR or GPT will mishandle RAW disks, potentially failing silently or producing incorrect recommendations.

MBR disk larger than 2 TB:

If an MBR disk is larger than 2 TB, only the first 2 TB is usable, the rest is wasted. The script detects this condition and warns the administrator. Converting to GPT (which requires erasing the disk with standard tools, or using mbr2gpt.exe for the OS disk) makes the full capacity available.

Method 3: DiskPart Quick Check (No PowerShell)

For environments where PowerShell is unavailable or restricted, DiskPart's list disk shows the partition style via an asterisk in the Gpt column.

@echo off
setlocal

net session >nul 2>&1
if errorlevel 1 (
echo [ERROR] DiskPart requires administrator privileges. >&2
endlocal
exit /b 1
)

echo [INFO] Disk partition styles (DiskPart):
echo.

set "DPScript=%TEMP%\dp_list_%RANDOM%.txt"
(echo list disk) > "%DPScript%"

diskpart /s "%DPScript%" 2>nul

del "%DPScript%" 2>nul

echo.
echo Reading the output:
echo * in the Gpt column = GPT partition style
echo (blank) Gpt column = MBR partition style
echo New uninitialized disks show as MBR with 0 B free
echo.
echo For a more detailed report, use PowerShell: Get-Disk ^| Format-Table

endlocal
exit /b 0

Limitations of the DiskPart approach:

  • DiskPart requires administrator privileges just to list disks. PowerShell's Get-Disk may work without elevation for read-only queries on some systems.
  • DiskPart cannot distinguish between MBR and RAW, both show a blank Gpt column. A brand-new uninitialized disk appears identical to an MBR disk.
  • The output is text-based and difficult to parse programmatically. PowerShell returns typed objects that can be filtered, compared, and exported.

Method 4: Fleet-Wide Partition Style Audit

For auditing disk configurations across multiple machines, export partition style data to a shared CSV.

@echo off
setlocal

set "CSVFile=\\Server\Audit\disk_styles.csv"

if not exist "%CSVFile%" (
echo "Timestamp","Computer","DiskNum","DiskName","SizeGB","Style","BusType","IsBoot" > "%CSVFile%" 2>nul
)

powershell -NoProfile -Command ^
"$ts = Get-Date -Format 'yyyy-MM-dd HH:mm:ss';" ^
"Get-Disk -ErrorAction SilentlyContinue | ForEach-Object {" ^
" $sizeGB = [math]::Round($_.Size / 1GB, 1);" ^
" Write-Output ('\"' + $ts + '\",\"' + $env:COMPUTERNAME + '\",\"' + $_.Number + '\",\"' + $_.FriendlyName + '\",\"' + $sizeGB + '\",\"' + $_.PartitionStyle + '\",\"' + $_.BusType + '\",\"' + $_.IsBoot + '\"')" ^
"}" >> "%CSVFile%" 2>nul

echo [OK] Disk style data exported for %COMPUTERNAME%.

endlocal
exit /b 0

What to look for in the fleet CSV:

  • Boot disks with MBR style on UEFI machines: These machines may have been installed in legacy BIOS mode and should be evaluated for GPT conversion (using mbr2gpt.exe) to enable modern security features like Secure Boot.
  • Data disks > 2 TB with MBR: Wasted capacity beyond 2 TB. Convert to GPT.
  • RAW disks: Uninitialized drives that were physically installed but never configured.
  • Inconsistent styles: If your standard is GPT but some machines have MBR data disks, they may have been set up before your current standard was established.

How to Avoid Common Errors

Wrong Way: Assuming All Disks Are Either MBR or GPT

A new, uninitialized disk reports as RAW. Scripts that only check for MBR or GPT and use else logic will miscategorize RAW disks.

Correct Way: Always handle three states: GPT, MBR, and RAW. Method 2 demonstrates this with explicit handling for each.

Problem: Converting MBR to GPT Without Data Loss

Standard DiskPart convert gpt requires erasing the disk first (clean). This destroys all data.

Solution: For data disks, back up all data, then clean and convert. For the OS boot disk specifically, Windows 10 version 1703+ includes mbr2gpt.exe, which can convert the system disk from MBR to GPT in-place without data loss:

:: Convert the OS disk from MBR to GPT without data loss (Windows 10 1703+)
:: Must be run from WinPE or with /allowFullOS flag
mbr2gpt /validate /disk:0
mbr2gpt /convert /disk:0 /allowFullOS

Note: the firmware must also be switched from BIOS to UEFI in the computer's BIOS settings after conversion.

Problem: DiskPart Cannot Distinguish MBR from RAW

In DiskPart's list disk output, both MBR and RAW disks show a blank Gpt column. You cannot tell whether a disk is MBR-initialized or completely uninitialized.

Solution: Use PowerShell's Get-Disk which returns PartitionStyle as MBR, GPT, or RAW, three distinct values.

Problem: Mismatched Firmware and Partition Style

A UEFI system with an MBR boot disk (or a BIOS system with a GPT boot disk) will fail to boot with "No bootable device found" or similar errors.

Solution: Method 1 includes the Boot column so you can identify the boot disk and verify its style matches the firmware. Check firmware type with:

powershell -NoProfile -Command ^
"$fw = (Get-CimInstance Win32_ComputerSystem).BootupState;" ^
"$bios = Get-CimInstance Win32_BIOS;" ^
"if (Test-Path 'HKLM:\System\CurrentControlSet\Control\SecureBoot\State') {" ^
" Write-Host 'Firmware: UEFI (Secure Boot capable)'" ^
"} else {" ^
" Write-Host 'Firmware: BIOS (Legacy)'" ^
"}"

Best Practices and Rules

1. Check Before Every Disk Operation

Before initializing, cloning, resizing, or deploying to a disk, verify its partition style. Incorrect assumptions lead to unbootable systems, wasted capacity, or data loss.

2. Standardize on GPT

For all new deployments on UEFI hardware (which includes virtually all modern PCs and servers), use GPT. Document this as your organization's standard and use the fleet audit (Method 4) to verify compliance.

3. Handle RAW Disks Explicitly

Don't treat RAW as MBR or GPT. A RAW disk needs initialization before it can be partitioned. Your scripts should detect this state and either initialize automatically (with confirmation) or report it for manual action.

4. Match Partition Style to Firmware

The boot disk's partition style must match the system firmware: GPT for UEFI, MBR for BIOS. Data disks (non-boot) can use either style regardless of firmware.

5. Audit Before OS Deployment

When preparing machines for OS deployment (SCCM, MDT, WDS), audit all target disks first. Deploy to a GPT disk with the wrong task sequence (or vice versa) will fail. Use Method 4's CSV export to plan the deployment strategy.

Conclusions

Identifying the partition style of your disks is a critical first step for any storage management, cloning, or OS deployment task. By using PowerShell's Get-Disk for accurate three-state detection (GPT, MBR, RAW), checking for MBR disks larger than 2 TB, and verifying firmware-partition alignment, you prevent costly mistakes and ensure your infrastructure follows modern storage standards. This intelligence is essential for anyone managing physical hardware at scale.