Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect GPT and MBR partitions with Powershell

Is there a way to tell if a disk has a GPT or an MBR partition with powershell?

like image 838
Josh Avatar asked Oct 01 '10 15:10

Josh


People also ask

How can I tell if a Partition is MBR or GPT?

Locate the disk you want to check in the Disk Management window. Right-click it and select “Properties.” Click over to the “Volumes” tab. To the right of “Partition style,” you'll see either “Master Boot Record (MBR)” or “GUID Partition Table (GPT),” depending on which the disk is using.

How do I know if my Partition is MBR or GPT Windows 10?

In the pop-out window, type “list disk” and press Enter. Then you will see all the disks on your computer. To check their partition styles (MBR or GPT), you just need to see whether there is an asterisk character (*) under the “Gpt” column.

How do I know what Partition style I have Windows 10?

Click Start, right-click This PC, and then click Manage. The Computer Management window opens. Click Disk Management. The list of available drives and partitions appears.


2 Answers

If you are on Windows 8, Windows Server 2012, or newer, then you can use one of the storage cmdlets to check this:

Get-Disk

The output of this command will be formatted like:

PS C:\> Get-Disk

Number Friendly Name                            OperationalStatus                    Total Size Partition Style
------ -------------                            -----------------                    ---------- ---------------
0      Microsoft Virtual Disk                   Online                                    42 GB GPT
1      Microsoft Virtual Disk                   Online                                     1 GB GPT
2      Microsoft Virtual Disk                   Offline                                    2 GB RAW
3      Microsoft Virtual Disk                   Offline                                    3 GB RAW

Notice that the rightmost column indicates the Partition Style, which is the piece of data that you are seeking.

If you are on Windows 7, Windows Server 2008 R2, or older, then you should use diskpart or WMI to get this information. I prefer to use diskpart. Type

diskpart

followed by

list disk

The output will look like:

PS C:\> diskpart

Microsoft DiskPart version 6.3.9600

Copyright (C) 1999-2013 Microsoft Corporation.
On computer: WIN-BN8G3VMNQ9T

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online           42 GB      0 B        *
  Disk 1    Online         1024 MB   991 MB        *
  Disk 2    Offline        2048 MB  2048 MB
  Disk 3    Offline        3072 MB  3072 MB

Note that Disk 0 and 1 are both GPT disks, and they have an asterisk in the appropriate column.

like image 104
Frank Lesniak Avatar answered Sep 23 '22 19:09

Frank Lesniak


Using WMI

gwmi -query "Select * from Win32_DiskPartition WHERE Index = 0" | Select-Object DiskIndex, @{Name="GPT";Expression={$_.Type.StartsWith("GPT")}}

Using Diskpart

$a = "list disk" | diskpart
$m = [String]::Join("`n", $a) | Select-String -Pattern "Disk (\d+).{43}(.)" -AllMatches
$m.Matches | Select-Object @{Name="DiskIndex";Expression={$_.Groups[1].Value}}, @{Name="GPT";Expression={$_.Groups[2].Value -eq "*"}}
like image 45
Josh Avatar answered Sep 26 '22 19:09

Josh