Monitor USB File Changes with PowerShell: Additions, Edits and Deletions

Infostruction banner: a person holding a mug stands in a dim home office lit by server racks and monitors, with the Infostruction logo and wordmark across the centre.

Sometimes you need a lightweight record of what changed on a removable drive while it was attached to a Windows device. This PowerShell script polls one drive and writes observed additions, modifications and deletions into a local CSV.

Updated November 3, 2026. The download now includes deletion detection, a configurable monitoring duration and persistent CSV output. The previous article described those features more broadly than its script actually implemented.

What this observes

The script compares file paths, lengths and last-write timestamps between complete directory snapshots. A new path is recorded as Created, a changed length or timestamp as Modified, and a missing path as Deleted. A rename can appear as a deletion and a creation.

This is file-change monitoring, not a complete USB activity audit. Reading a file or copying it from the USB drive may leave those values unchanged. The script cannot identify the person or process responsible, establish transfer direction, prove exfiltration, or recover deleted contents. Changes that happen and disappear between polls can be missed.

Download and run

Download the revised USB file-change monitor. Save it as USB-Drive-Monitoring.ps1. Replace earlier copies; their logging behavior differs from this revision.

Use Windows PowerShell 5.1 or later with permission to enumerate the drive and write the report. Some USB storage reports itself as a fixed disk; this script’s automatic selection uses Windows removable-drive classification and will not cover every USB-connected device.

# Create C:\Logs first, or choose another existing local folder.
.\USB-Drive-Monitoring.ps1 -DriveLetter E -DurationMinutes 1440 -PollSeconds 10 -OutputPath 'C:\Logs\USB-events.csv'

Replace E with the actual drive letter. The defaults target 24 hours of monitoring, with a ten-second pause between snapshots. Each snapshot also takes time, so this is not an exact ten-second event feed; a scan already in progress can extend beyond the target duration.

If the drive is not present, the script waits up to five minutes by default. Set -WaitForDriveSeconds to change that limit. If no drive letter is supplied, it selects a single detected removable drive and rejects an ambiguous selection when several are present.

Read the CSV

The columns are ObservedUtc, ChangeType, Path, Length, LastWriteTimeUtc and Details. The observation time tells you when the script noticed the difference, not necessarily the instant the underlying operation happened.

MonitoringStarted marks the baseline. File-change rows are appended as they are found, and a status row records DurationElapsed or DisconnectedOrReplaced. The script checks the volume serial number to help avoid treating another drive mounted at the same letter as the original volume.

Save the CSV outside the monitored drive. The script rejects a report path inside that drive and refuses to overwrite an existing report. The log can expose filenames and local paths, so give it an appropriate owner, access restrictions and retention period.

Incomplete snapshots stop the monitor

If enumeration fails, the script writes SnapshotFailed when possible and stops. It does not compare an incomplete result with the previous snapshot and invent a series of deletion events. Preserve the error and the partial CSV when investigating.

Directory snapshots are not atomic. A drive changing during enumeration can still yield imperfect observations, and large drives make this approach expensive. Test the expected file count and activity rate before leaving it running.

Using it through RMM

Configure the component or scheduled task to allow the intended runtime, capture errors and retain the CSV after the job ends. A platform that terminates jobs after a short interval will not provide a 24-hour monitor just because the script requests one. Start with a short pilot and create, edit and delete known test files to confirm the output.

Use purpose-built endpoint or device-control telemetry where you need actor attribution, file-read events or stronger audit evidence. Keep those requirements separate from what this polling script can establish.

Validation for this revision: Local checks covered creation/modification/deletion comparisons, incomplete snapshots, report-path protection and simulated drive disconnection. No real USB device or RMM deployment was exercised during this refresh.

Share your thoughts, leave a comment

Your email address will not be published. Required fields are marked *

You may also like these

INFOSTRUCTION

You're about to become an infostruction VIP!

By subscribing, you’ll receive a monthly round-up of the latest news. There’ll be no spam, I promise :)