Back to Resources
Level
Script
Security
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 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.
1<#
2This resource is provided as a convenience for Level users. We cannot
3guarantee it will work in all environments. Please test before deploying
4to your production environment. We welcome contributions to our community
5library
6
7Level Library
8https://level.io/library/script-windows-monitor-usb-drive
9#>
10
11# Look for USB Drives
12$USBDrivePresent = Get-CimInstance -ClassName Win32_DiskDrive | Where-Object { $_.InterfaceType -eq 'USB' }
13
14if ($USBDrivePresent) {
15 # If USB drive is present, send console message for Level to alert on
16 Write-Host "ALERT"
17}
Write-Host "ALERT"
line in the script to suit your specific logging or notification needs.Windows Monitor - USB Drive
This script checks for the presence of USB drives connected to the system using the Win32_DiskDrive class. If any USB drives are detected, it outputs "ALERT" for monitoring and potential alerting through Level.
PowerShell
100
Local system
Explore more automations, scripts, and policies to further enhance your IT operations.