PowerShell Genie

Find USB storage devices

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Query Win32_DiskDrive for USB storage devices. Report model, device ID, size in bytes, and available serial numbers with PowerShell.

The script

1PS> Get-CimInstance Win32_DiskDrive | Where-Object InterfaceType -eq USB | Select-Object Model,DeviceID,Size,SerialNumber

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 Model DeviceID Size SerialNumber
    2 ----- -------- ---- ------------
    3 SanDisk Extreme USB \.\PHYSICALDRIVE2 128034708480 4C530001230101117254
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    Get-CimInstance Win32_DiskDrive | Where-Object InterfaceType -eq USB | Select-Object Model,DeviceID,Size,SerialNumber
    1. Stage 1Get-CimInstancePositional values or no named parameters
    2. Stage 2Where-Object-eq
    3. Stage 3Select-ObjectPositional values or no named parameters

      How it works

      Get-CimInstance enumerates Win32_DiskDrive, Where-Object keeps rows whose InterfaceType reads USB, and Select-Object reports the model with the device ID, raw size in bytes, and whatever serial number the firmware exposes.

      Adapting it

      For devices connected at some point in the past rather than right now, read the USBSTOR keys under HKLM:\SYSTEM\CurrentControlSet\Enum\USB, which retain entries long after the hardware is gone.

      If the result is unexpected

      A connected USB storage device is absent from the disk report.

      The device may not expose InterfaceType as USB, or the storage driver may not have enumerated it yet.

      1. Inspect the unfiltered disk inventory and compare Model, DeviceID and InterfaceType with the connected device.

      Validate the result

      The report includes the expected device or documents why its interface classification excludes it.

      Keep the check reliable

      Document the interface filter and avoid treating an empty report as proof that no removable storage exists.

      Primary documentation

      Get-CimInstance reference

      Continue
      Genie guideFind USB storage devices

      Query Win32_DiskDrive for USB storage devices. Report model, device ID, size in bytes, and available serial numbers with PowerShell.