Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codykonior/8ae29263afc3da69db9bdb84e3791993 to your computer and use it in GitHub Desktop.
Save codykonior/8ae29263afc3da69db9bdb84e3791993 to your computer and use it in GitHub Desktop.
How to follow from a drive letter to a physical disk in PowerShell
$drive = "C:"
Get-CimInstance -ClassName Win32_LogicalDisk | Where-Object { $_.DeviceID -eq $drive }
$partition = Get-CimInstance Win32_LogicalDiskToPartition | Where-Object { $_.Dependent.DeviceID -eq $drive } | Select-Object -ExpandProperty Antecedent | Select-Object -ExpandProperty DeviceID
$diskDrive = Get-CimInstance -ClassName Win32_DiskDriveToDiskPartition | Where-Object { $_.Dependent.DeviceID -eq $partition } | Select-Object -ExpandProperty Antecedent | Select-Object -ExpandProperty DeviceID
Get-CimInstance -Class Win32_DiskDrive | Where-Object { $_.DeviceID -eq $diskDrive }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment