⚡ PowerShell 5.1+
Watch USB Controllers for Changes
Polls Win32_USBController on an interval and prints a line whenever the USB Controllers count changes — a lightweight way to notice new/removed items.
Watch-USBControllerChanges.ps1
<#
.SYNOPSIS
Watches USB Controllers (Win32_USBController) and reports when the item count changes.
.DESCRIPTION
Polls Win32_USBController every -IntervalSeconds and prints a line whenever the
number of items returned changes since the last check. Press Ctrl+C
to stop.
.PARAMETER IntervalSeconds
How often to poll, in seconds. Defaults to 10.
.EXAMPLE
.\Watch-USBControllerChanges.ps1 -IntervalSeconds 30
#>
[CmdletBinding()]
param(
[int]$IntervalSeconds = 10
)
Write-Host "Watching USB Controllers every $IntervalSeconds second(s). Press Ctrl+C to stop." -ForegroundColor Cyan
$lastCount = -1
while ($true) {
$count = (Get-CimInstance -ClassName Win32_USBController).Count
if ($count -ne $lastCount) {
$timestamp = Get-Date -Format 'HH:mm:ss'
Write-Host "[$timestamp] USB Controllers count: $count" -ForegroundColor Yellow
$lastCount = $count
}
Start-Sleep -Seconds $IntervalSeconds
}