In this tutorial, I will explain how to list USB devices using PowerShell on your Windows machine. Recently, one of my PowerShell admin team members asked me this question. I will show you how to list USB devices using PowerShell.
List USB Devices Using PowerShell
The simplest way to list USB devices using PowerShell is by using the Get-PnpDevice cmdlet, which retrieves information about Plug and Play devices. Here’s how you can use it:
Get-PnpDevice -Class USBThis command lists all USB devices connected to your computer. However, the information might be quite basic. To get more detailed information, you can combine this with other cmdlets.
I executed the above cmdlet, and you can see the output in the screenshot below:

Detailed USB Device Information
To get detailed information about each USB device, you can use the Get-WmiObject cmdlet. This cmdlet provides access to the Windows Management Instrumentation (WMI) database, which contains detailed information about hardware and software on your computer.
Get-WmiObject -Query "Select * from Win32_USBHub"This command retrieves detailed information about all USB hubs connected to your system. You can also query other WMI classes to get information about USB controllers and devices.
Check out List Local Administrators Using PowerShell
List USB Devices in a Corporate Environment using PowerShell
Imagine you are an IT administrator at a company in New York City, and you need to audit all USB devices connected to the computers in your office. You can use the following PowerShell script to list all USB devices on a network:
$computers = Get-Content -Path "C:\computers.txt"
foreach ($computer in $computers) {
Invoke-Command -ComputerName $computer -ScriptBlock {
Get-WmiObject -Query "Select * from Win32_USBHub"
}
}In this script, C:\computers.txt is a text file containing the names of the computers you want to audit. The Invoke-Command cmdlet runs the Get-WmiObject command on each computer in the list.
Check out Rename a Computer Using PowerShell
Filter USB Devices by Manufacturer using PowerShell
Sometimes, you might want to filter the list of USB devices by manufacturer. For example, if you are only interested in devices made by SanDisk, you can use the following command:
Get-WmiObject -Query "Select * from Win32_USBHub" | Where-Object { $_.Manufacturer -eq "SanDisk" }This command retrieves only the USB devices manufactured by SanDisk.
Log USB Devices to a File using PowerShell
Here’s an example script that logs the USB devices to a file using PowerShell.
$logFile = "C:\Logs\USBDevicesLog.txt"
$usbDevices = Get-WmiObject -Query "Select * from Win32_USBHub" | Select-Object -Property DeviceID, PNPDeviceID, Description, Manufacturer
$usbDevices | Out-File -FilePath $logFile -AppendThis script appends the list of USB devices to C:\Logs\USBDevicesLog.txt each time it runs.
Use CIM Cmdlets for Better Performance
The Get-WmiObject cmdlet is powerful but can be slow on large networks. The Get-CimInstance cmdlet is a more efficient alternative that uses the Common Information Model (CIM) instead of WMI. Here’s how to use it:
Get-CimInstance -ClassName Win32_USBHubCheck out Get HP Laptop Model and Serial Number Using PowerShell
Export USB Device Information to CSV using PowerShell
As a PowerShell administrator, sometimes you might want to export the USB device information to a CSV file. Here’s how to do it:
$usbDevices = Get-CimInstance -ClassName Win32_USBHub | Select-Object -Property DeviceID, PNPDeviceID, Description, Manufacturer
$usbDevices | Export-Csv -Path "C:\Reports\USBDevices.csv" -NoTypeInformationThis command exports the USB device information to C:\Reports\USBDevices.csv.
In this tutorial, I explained how to list USB devices using PowerShell with some examples.
You may also like:
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.