⚡ PowerShell 5.1+

Watch Network Adapters for Changes

Polls Win32_NetworkAdapter on an interval and prints a line whenever the Network Adapters count changes — a lightweight way to notice new/removed items.

By WindowsScripting.com · 967 B
Watch-NetworkAdapterChanges.ps1
<#
.SYNOPSIS
    Watches Network Adapters (Win32_NetworkAdapter) and reports when the item count changes.

.DESCRIPTION
    Polls Win32_NetworkAdapter 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-NetworkAdapterChanges.ps1 -IntervalSeconds 30
#>

[CmdletBinding()]
param(
    [int]$IntervalSeconds = 10
)

Write-Host "Watching Network Adapters every $IntervalSeconds second(s). Press Ctrl+C to stop." -ForegroundColor Cyan

$lastCount = -1
while ($true) {
    $count = (Get-CimInstance -ClassName Win32_NetworkAdapter).Count
    if ($count -ne $lastCount) {
        $timestamp = Get-Date -Format 'HH:mm:ss'
        Write-Host "[$timestamp] Network Adapters count: $count" -ForegroundColor Yellow
        $lastCount = $count
    }
    Start-Sleep -Seconds $IntervalSeconds
}