Last active
October 29, 2019 18:46
-
-
Save russellds/1a21f8fb5da2f1dfb7b9263a66fb04d7 to your computer and use it in GitHub Desktop.
List Windows Disk with Boot Disk First
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Empty Array to hold disks in boot disk always first order. | |
$disks = @() | |
# Identify the boot partition | |
$bootPartition = Get-WmiObject -Class Win32_DiskPartition | | |
Where-Object {$_.BootPartition} | |
# Identify the boot disk using the boot partition | |
$bootDisk = Get-WmiObject -Class Win32_DiskDrive | | |
Where-Object {$_.Index -eq $bootPartition.DiskIndex} | | |
Select-Object -ExpandProperty DeviceID | |
# Add boot disk as first item in array | |
$disks += $bootDisk | |
# Add remaining disks to array excluding the boot disk | |
$disks += Get-WmiObject -Class Win32_DiskDrive | | |
Select-Object -ExpandProperty DeviceID | | |
Where-Object {$_ -ne $bootDisk} | | |
Sort-Object -Unique | |
$disks | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment