PowerTip: Show attached USB Drives with PowerShell

PowerTip: Show attached USB Drives with PowerShell

  • Comments 3
  • Likes

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’ }


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

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

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • The 1st line works but the 2nd errors with 'invalid query'

  • 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.

  • 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.