Question:
Is there a way to tell if a disk has a GPT or an MBR partition with powershell?
Answer:
Using WMI
1 2 |
gwmi -query "Select * from Win32_DiskPartition WHERE Index = 0" | Select-Object DiskIndex, @{Name="GPT";Expression={$_.Type.StartsWith("GPT")}} |
Using Diskpart
1 2 3 4 |
$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 "*"}} |