In digital forensics, security auditing, and system administration, verifying which external USB mass storage devices have previously been plugged into a workstation is essential for investigating data exfiltration or malware propagation. While active flash drives appear in File Explorer, disconnected storage devices leave permanent traces within the Windows Registry. Using Windows PowerShell, administrators can query the USBSTOR hardware enumeration registry keys to extract a complete historical log of all external storage devices, including manufacturer names, product models, firmware revisions, and unique hardware serial numbers.
Why Audit Historical USB Storage Connections?
Windows tracks every Plug-and-Play device connection across the machine’s lifespan. Querying this repository provides tangible security benefits:
- Data Exfiltration Analysis: Determine if unauthorized flash drives or external solid-state drives were mounted on an endpoint before an employee departure or incident alert.
- Malware Traceability: Identify physical USB devices present on the system around the timestamp of suspicious payload executions.
- Hardware Asset Verification: Match logged hardware serial numbers against corporate-sanctioned, encrypted hardware inventories.
- No Third-Party Tools Required: Forensic auditing can be conducted natively on any Windows 11 endpoint without triggering application whitelisting blocks or installing external utilities.
Step 1: Open Windows PowerShell with Administrative Privileges
Because the hardware enumeration branch of the registry resides within HKEY_LOCAL_MACHINE, elevated permissions are required:
- Right-click the Start button on the taskbar.
- Select Terminal (Admin) or Windows PowerShell (Admin).
- Click Yes when prompted by the User Account Control (UAC) dialogue.
Step 2: Query the USBSTOR Registry Key for Connected Devices
Execute the following script block to inspect the USBSTOR registry container, parse device descriptions, and isolate unique hardware serial numbers:
$RegPath = "HKLM:\SYSTEM\CurrentControlSet\Enum\USBSTOR"
if (Test-Path $RegPath) {
Get-ChildItem -Path $RegPath | ForEach-Object {
$DeviceName = $_.PSChildName
Get-ChildItem -Path $_.PSPath | ForEach-Object {
[PSCustomObject]@{
DeviceType = $DeviceName
SerialNumber = $_.PSChildName
FriendlyName = (Get-ItemProperty -Path $_.PSPath -Name "FriendlyName" -ErrorAction SilentlyContinue).FriendlyName
DeviceDesc = (Get-ItemProperty -Path $_.PSPath -Name "DeviceDesc" -ErrorAction SilentlyContinue).DeviceDesc
}
}
} | Format-Table -AutoSize
} else {
Write-Host "No historical USB storage devices detected." -ForegroundColor Yellow
}
This script parses the two-tier structure of the USBSTOR key:
- The parent keys identify the hardware manufacturer, product ID, and revision (e.g.,
Disk&Ven_SanDisk&Prod_Ultra&Rev_1.00). - The subkeys contain the unique hardware serial number assigned by the vendor (or a Windows-generated unique instance identifier).
Step 3: Retrieve Connection Timestamps from the SetupAPI Log
While the registry stores hardware identifiers, Windows records connection installation dates in the setup log file. To extract exact timestamps when devices were first introduced:
$LogFile = "$env:SystemRoot\inf\setupapi.dev.log"
if (Test-Path $LogFile) {
Select-String -Path $LogFile -Pattern "USBSTOR" -Context 0, 3 | ForEach-Object {
$_.Line
$_.Context.PostContext
}
}
This command audits setupapi.dev.log, outputting the initial driver installation event and system timestamp for each enumerated USB storage volume.
Step 4: Export the USB Audit Report to CSV
To produce an audit artefact for forensic reporting or compliance compliance documentation:
$RegPath = "HKLM:\SYSTEM\CurrentControlSet\Enum\USBSTOR"
$ReportPath = "$HOME\Desktop\usb_device_audit.csv"
Get-ChildItem -Path $RegPath | ForEach-Object {
$DeviceName = $_.PSChildName
Get-ChildItem -Path $_.PSPath | ForEach-Object {
[PSCustomObject]@{
DeviceType = $DeviceName
SerialNumber = $_.PSChildName
FriendlyName = (Get-ItemProperty -Path $_.PSPath -Name "FriendlyName" -ErrorAction SilentlyContinue).FriendlyName
DeviceDesc = (Get-ItemProperty -Path $_.PSPath -Name "DeviceDesc" -ErrorAction SilentlyContinue).DeviceDesc
}
}
} | Export-Csv -Path $ReportPath -NoTypeInformation
Write-Host "USB history audit successfully exported to $ReportPath" -ForegroundColor Green
Reviewing historical USB storage records with PowerShell empowers administrators to maintain stringent endpoint visibility and investigate security incidents rapidly.