Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PowerShell.org Forum Response
$driveLetters = Get-Volume | Select -ExpandProperty driveLetter
foreach ($driveLetter in $driveLetters) {
Get-CimInstance CIM_LogicalDiskBasedOnPartition |
Where-Object {$_.Dependent -like "*DeviceID = `"$driveLetter`:`"*"} |
Select @{l='DriveLetter';e={$driveLetter}},@{l='Index';e={$_.Antecedent -match "Disk #[\d]+" |
ForEach-Object {$matches[0]}}}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment