Last active
August 27, 2024 15:22
-
-
Save huevos-y-bacon/acaec303dedee67e497e816ad376a82c to your computer and use it in GitHub Desktop.
PowerShell - Get EBS volume-id for each drive letter
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
# Display the DiskID and DriveLetter for each disk | |
# Output looks like this: | |
# Letter DiskID | |
# ------ ------ | |
# C vol-0123456780f7d0447 | |
# E vol-01234567882ab1f8e | |
# Z vol-012345678e9b37c78 | |
# I vol-0123456780fc78bc2 | |
# G vol-0123456781aa7d6df | |
# Y vol-012345678fd783fe5 | |
# D vol-012345678cf798a4f | |
# H vol-01234567844acc02f | |
# F vol-0123456782a19b0be | |
# J vol-01234567870120c97 | |
$Disks = Get-PhysicalDisk | foreach { | |
$DiskID = $_.SerialNumber.Split('_')[0].Replace('vol','vol-') | |
$Letter = (Get-Partition -DiskNumber $_.DeviceID).DriveLetter | where {$_} | |
[pscustomobject] @{ | |
Letter = $Letter | |
DiskID = $DiskID | |
} | |
} | |
$Disks | |
# One-liner: | |
Get-PhysicalDisk | foreach { $DiskID = $_.SerialNumber.Split('_')[0].Replace('vol','vol-'); $Letter = (Get-Partition -DiskNumber $_.DeviceID).DriveLetter | where {$_}; [pscustomobject] @{ Letter = $Letter; DiskID = $DiskID } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment