PowerTip: Show attached USB Drives with PowerShell


Summary: Use Windows PowerShell to show attached USB drives.

Hey, Scripting Guy! Question Is there an easy way with Windows PowerShell to show all drives that are connected via USB?

Hey, Scripting Guy! AnswerUse Get-WMIObject and query win32_diskdrive:

GET-WMIOBJECT win32_diskdrive | Where { $_.InterfaceType –eq ‘USB’ }

Or…

Write this as a query and pass it directly to WMI:

GET-WMIOBJECT –query “SELECT * from win32_diskdrive where InterfaceType = ‘USB’”

Comments (3)

  1. David Wyatt says:

    It's probably because of the "smart quotes" that are in the post.  If you type the command out at the console or in the ISE rather than copy and paste, it works.  Or, copy and paste, but delete and retype each of the single and double quote characters before you run it.

  2. David Wyatt says:

    I just tested, and it's only the single quotes around the word USB that absolutely have to be changed.  PowerShell handles the rest okay, but WMI is more picky about it.

  3. Neil Brooks says:

    The 1st line works but the 2nd errors with 'invalid query'

Skip to main content