Read USB Device History with PowerShell

Four short commands answer most USB history questions on Windows: what connected, when, under which account, and how to keep the result.

  • Last verified: November 2026
  • PowerShell 5.1 or 7
  • Copy-ready commands
Illustration of a PowerShell window querying USB connect and removal events
Short answer

PowerShell Commands for USB Device History

Get-ItemProperty on the USBSTOR key lists every storage drive Windows has seen, and Get-WinEvent on the DriverFrameworks log returns connection and removal times. Pipe either result to Export-Csv to keep a record. Run PowerShell as administrator for Security log queries.

At a glance

Shell
PowerShell 5.1 or 7
Rights
Administrator for the Security log
Output
Table or CSV
Covers
Registry history and event history

Query, Filter, Export: The Pattern Behind Every Script

Every command on this page follows one pattern. Query a source, filter to the event IDs or fields you care about, then export the rows. Learn the pattern once and you can swap sources without rewriting the logic.

Last verified: November 2026. Logging has to be on before the event queries return anything, so use the full setup steps first if your logs are empty.

Diagram of three PowerShell stages for USB history: query, filter and export
The three stages repeat for every source.

List Every USB Storage Device Ever Connected

The registry holds one subkey per storage device. This command reads them all, which is the quickest way to answer which drives have touched a PC.

PowerShell
Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Enum\USBSTOR\*\*' |
  Select-Object FriendlyName, PSChildName, ContainerID
Fields in a USBSTOR registry entry: friendly name, serial and container identifier
What each column in the registry listing means.

The PSChildName column is the device serial with a suffix. Compare it with your register of approved drives. The command errors with a missing path when no storage drive has ever connected, and it never lists MTP phones.

Pull Connection and Removal Events

Event IDs 2003 and 2102 in the DriverFrameworks log mark each connect and removal. The filter table below keeps the query fast on large logs.

PowerShell
Get-WinEvent -FilterHashtable @{
  LogName = 'Microsoft-Windows-DriverFrameworks-UserMode/Operational'
  Id      = 2003, 2102
} -MaxEvents 50 | Select-Object TimeCreated, Id, Message

Using -FilterHashtable asks the log service to filter, which is much faster than piping every event to Where-Object. Raise -MaxEvents when you need a longer window.

Pull Event 6416 with Account Names

The message text of event 6416 is long. Reading the XML fields gives you clean columns, including the account that was signed in.

PowerShell, run as administrator
Get-WinEvent -FilterHashtable @{LogName='Security'; Id=6416} | ForEach-Object {
  $d = ([xml]$_.ToXml()).Event.EventData.Data
  [pscustomobject]@{
    Time     = $_.TimeCreated
    User     = ($d | Where-Object { $_.Name -eq 'SubjectUserName' }).'#text'
    Device   = ($d | Where-Object { $_.Name -eq 'DeviceDescription' }).'#text'
    DeviceId = ($d | Where-Object { $_.Name -eq 'DeviceId' }).'#text'
  }
}

Export Results to a CSV File

A CSV file opens in Excel and survives a log rollover. Append Export-Csv to any query above.

PowerShell
... | Export-Csv C:\UsbLogs\usb-history.csv -NoTypeInformation

To collect from another PC, add -ComputerName PC01 to Get-WinEvent. The remote PC must allow remote event log management through its firewall, and you need rights there.

USB Block Reports and Logs tab showing device report columns for comparison with a CSV
A dedicated tool shows similar columns without a script: device type, name, times inserted.

PowerShell Errors and What They Mean

Three messages account for most failed runs.

PowerShell errors on USB queries
MessageCauseFix
No events were found that match the specified selection criteriaLog empty, ID wrong or logging never enabledCheck the log name and run the enable steps
Attempted to perform an unauthorized operationSecurity log needs administrator rightsReopen PowerShell with Run as administrator
Cannot find path ...\USBSTOR\*\*No storage drive has ever connectedExpected on a fresh PC; test with a drive

Limits of Scripted USB History

Scripts give you raw rows. They do not block a drive, ask for a password or keep working after a log rolls over. If you want those, USB Block adds a block and a local report on one PC, with the limits listed on the comparison page. The developer, NewSoftwares.net, publishes the product details.

Scripts also need a person to run them. A scheduled task that exports the log nightly closes that gap on a single PC at no cost.

Schedule a Nightly Export on One PC

A scheduled task removes the human step. Save the CSV pipeline from above as C:\UsbLogs\export.ps1, then register the task once from an administrator prompt.

Command Prompt, run as administrator
schtasks /create /tn "UsbLogExport" /sc daily /st 22:00 /ru SYSTEM /tr "powershell -NoProfile -File C:\UsbLogs\export.ps1"

The task runs as SYSTEM, which can read the Security log. Add a date to the output file name so each night writes a new file, and delete files older than your retention period.

Questions About PowerShell and USB History

How do I list all USB devices ever connected with PowerShell?

Read the USBSTOR registry key with Get-ItemProperty on HKLM:\SYSTEM\CurrentControlSet\Enum\USBSTOR\*\* and select FriendlyName and PSChildName. That shows every storage drive Windows has installed, though not when it connected or any phone in MTP mode.

Can PowerShell show when a USB drive was removed?

Yes, if the DriverFrameworks Operational log was enabled beforehand. Query event ID 2102 with Get-WinEvent and read TimeCreated. Without that log, Windows keeps no record of removal times.

Do I need administrator rights to query USB history?

Registry reads of USBSTOR work from a normal session on most PCs, but the Security log and any remote query need an administrator session. If PowerShell says the operation is unauthorized, reopen it as administrator.

Does PowerShell work on Windows Home?

Yes. PowerShell 5.1 ships with Windows 10 and 11 Home, and the commands here use no editor that Home lacks. Logging must still be enabled with auditpol and wevtutil.

How do I keep USB history after the log fills up?

Export on a schedule. Create a task that runs wevtutil epl or the CSV pipeline each night, saving to a dated file. Raising the log’s maximum size helps but does not replace exports.