⚡ PowerShell 5.1+
Watch Network Shares for Changes
Polls Win32_Share on an interval and prints a line whenever the Network Shares count changes — a lightweight way to notice new/removed items.
Watch-ShareChanges.ps1
<#
.SYNOPSIS
Watches Network Shares (Win32_Share) and reports when the item count changes.
.DESCRIPTION
Polls Win32_Share 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-ShareChanges.ps1 -IntervalSeconds 30
#>
[CmdletBinding()]
param(
[int]$IntervalSeconds = 10
)
Write-Host "Watching Network Shares every $IntervalSeconds second(s). Press Ctrl+C to stop." -ForegroundColor Cyan
$lastCount = -1
while ($true) {
$count = (Get-CimInstance -ClassName Win32_Share).Count
if ($count -ne $lastCount) {
$timestamp = Get-Date -Format 'HH:mm:ss'
Write-Host "[$timestamp] Network Shares count: $count" -ForegroundColor Yellow
$lastCount = $count
}
Start-Sleep -Seconds $IntervalSeconds
}