Problem overview
USB drives can pose serious security and data-leak risks, especially if inserted into protected or high-compliance systems without authorization. Manually tracking who has plugged in a USB device is impractical, particularly across multiple endpoints. This script solves the problem by automatically detecting connected USB drives and triggering an immediate alert.
<#
This resource is provided as a convenience for Level users. We cannot
guarantee it will work in all environments. Please test before deploying
to your production environment. We welcome contributions to our community
library
Level Library
https://level.io/library/script-windows-monitor-usb-drive
#>
# Look for USB Drives
$USBDrivePresent = Get-CimInstance -ClassName Win32_DiskDrive | Where-Object { $_.InterfaceType -eq 'USB' }
if ($USBDrivePresent) {
# If USB drive is present, send console message for Level to alert on
Write-Host "ALERT"
} This PowerShell script examines the Win32_DiskDrive class to see if any drives are connected via USB. If it locates at least one USB device, it produces an “ALERT” message. By setting up this script as a monitor in Level, you can immediately spot unauthorized or unexpected USB storage activity.
You can also pair it with a scheduled Automation in Level for periodic checks, ensuring continuous oversight. If an alert appears, you can take additional steps—such as generating a help desk ticket or running a remediation script—to safeguard your data.
Use cases
- Monitoring data-sensitive machines for unauthorized external storage
- Preventing data exfiltration in regulated industries
- Enforcing organizational policies against USB drive usage
- Alerting on newly attached USB devices in real time
Recommendations
- Test this script in a non-production environment before implementing widely
- Use a script-based monitor in Level to trigger real-time alerts
- Schedule via a Level Automation for repeated checks at regular intervals
- Pair with a remediation script or policy to disable or eject the drive if necessary
- Review logs to identify when and where USB drives appear, then address accordingly