⚡ PowerShell 5.1+

Watch Network Login Profiles for Changes

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

By WindowsScripting.com · 1005 B
Watch-NetworkLoginProfileChanges.ps1
<#
.SYNOPSIS
    Watches Network Login Profiles (Win32_NetworkLoginProfile) and reports when the item count changes.

.DESCRIPTION
    Polls Win32_NetworkLoginProfile 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-NetworkLoginProfileChanges.ps1 -IntervalSeconds 30
#>

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

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

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