FileSystemWatcher offer a way to see those changes without installing another utility.This guide works in Windows PowerShell 5.1 and PowerShell 7 on Windows 10 and Windows 11. It watches for created, changed, renamed, and deleted items, including changes in subfolders. You’ll inspect events in the same PowerShell session and clean up when finished.
Before you begin: Choose an existing project folder you can access. Administrator privileges are not normally necessary for a folder your account can read. Allow about 15 minutes.
Start the watcher
Open PowerShell and replace the example path below with your project folder. Paste the whole block into the session:
$projectPath = 'C:\Projects\MyProject'
if (-not (Test-Path -LiteralPath $projectPath -PathType Container)) {
throw "Project folder not found: $projectPath"
}
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = $projectPath
$watcher.Filter = '*'
$watcher.IncludeSubdirectories = $true
$watcher.NotifyFilter = [System.IO.NotifyFilters]'FileName, DirectoryName, LastWrite'
# A unique prefix keeps this watcher's subscriptions separate.
$prefix = 'ProjectWatch-' + [guid]::NewGuid.ToString('N')
$eventNames = 'Created', 'Changed', 'Renamed', 'Deleted', 'Error'
$ids = @
try {
foreach ($eventName in $eventNames) {
$id = "$prefix-$eventName"
Register-ObjectEvent -InputObject $watcher `
-EventName $eventName `
-SourceIdentifier $id `
-ErrorAction Stop
$ids += $id
}
$watcher.EnableRaisingEvents = $true
Write-Host "Watching $projectPath"
}
catch {
$watcher.EnableRaisingEvents = $false
foreach ($id in $ids) {
Unregister-Event -SourceIdentifier $id -ErrorAction SilentlyContinue
Get-Event -SourceIdentifier $id -ErrorAction SilentlyContinue |
Remove-Event
}
$watcher.Dispose
throw
}
Keep this PowerShell window open. The watcher runs while you work, but it does not print each event automatically: this example places events in the session’s event queue for you to inspect.
The settings watch names and last-write changes in the project folder and its subfolders. They can report directory changes as well as file changes. Microsoft documents that a FileSystemWatcher does not begin monitoring until its path is set and EnableRaisingEvents is enabled.
Test it and inspect the results
With the watcher running, use File Explorer or your editor to create a disposable text file inside the project folder. Save a change to it, rename it, and then delete it.
Back in the same PowerShell window, run:
$events = @(
foreach ($id in $ids) {
Get-Event -SourceIdentifier $id -ErrorAction SilentlyContinue
}
)
$events |
Where-Object { $_.SourceIdentifier -notlike '*-Error' } |
Sort-Object TimeGenerated |
Select-Object TimeGenerated,
@{Name='Change'; Expression={ $_.SourceEventArgs.ChangeType }},
@{Name='Path'; Expression={ $_.SourceEventArgs.FullPath }},
@{Name='OldPath'; Expression={ $_.SourceEventArgs.OldFullPath }} |
Format-Table -AutoSize
You should see entries for the test file. A rename includes the previous path in OldPath; that column is normally empty for other event types.
Don’t be surprised by extra rows. A single save or move can involve several filesystem operations, and Microsoft notes that other software, such as antivirus tools, can also generate notifications. An event is a filesystem signal—not necessarily one deliberate action by a person.
Each time you run the inspection block, it takes a fresh snapshot. Previously inspected events remain in the queue until you remove them or close the session.
Check for watcher errors
The setup also subscribes to the watcher’s Error event. Inspect it separately:
Get-Event -SourceIdentifier "$prefix-Error" -ErrorAction SilentlyContinue |
ForEach-Object {
[pscustomobject]@{
TimeGenerated = $_.TimeGenerated
Error = $_.SourceEventArgs.GetException.Message
}
}
No output means no error event is currently queued; it is not a guarantee that every change was captured. Microsoft says an Error event can occur if the internal buffer overflows or the watcher can no longer monitor a location—for example, after a remote connection is lost.
Filter the noise
Watch one file type
To monitor only PowerShell scripts, set the filter before enabling the watcher, or change it while the watcher is running:
$watcher.Filter = '*.ps1'
Return to all names with:
$watcher.Filter = '*'
The filter matches names, not a list of extensions separated by pipes. Microsoft explicitly notes that a value such as *.txt|*.doc is not supported by the Filter property.
A narrow filter can make output easier to read, but it also limits what you see. If a file is renamed between extensions, test the behavior for your workflow rather than assuming both names will be captured.
Filter the results instead
If you need several extensions—or want to keep all events available for later—leave the watcher filter as * and filter a snapshot when displaying it:
$events |
Where-Object {
$_.SourceIdentifier -notlike '*-Error' -and
(
$_.SourceEventArgs.FullPath -match '\.(ps1|json)$' -or
$_.SourceEventArgs.OldFullPath -match '\.(ps1|json)$'
)
} |
Sort-Object TimeGenerated |
Select-Object TimeGenerated,
@{Name='Change'; Expression={ $_.SourceEventArgs.ChangeType }},
@{Name='Path'; Expression={ $_.SourceEventArgs.FullPath }},
@{Name='OldPath'; Expression={ $_.SourceEventArgs.OldFullPath }} |
Format-Table -AutoSize
Refresh $events with the earlier inspection block first if you want to include changes that happened since your last snapshot. This display filter checks both paths, so it can show a rename where either the old or new name ends in .ps1 or .json.
Filtering the displayed results does not prevent other events from entering the queue. For a busy project, point the watcher at a smaller folder or use a narrower watcher filter where practical.
Clear events or stop monitoring
To discard the events currently queued for this watcher while continuing to monitor, run:
foreach ($id in $ids) {
Get-Event -SourceIdentifier $id -ErrorAction SilentlyContinue |
Remove-Event
}
To stop the watcher and remove its subscriptions and queued events, run:
$watcher.EnableRaisingEvents = $false
foreach ($id in $ids) {
Unregister-Event -SourceIdentifier $id -ErrorAction SilentlyContinue
Get-Event -SourceIdentifier $id -ErrorAction SilentlyContinue |
Remove-Event
}
$watcher.Dispose
These commands target the identifiers created by this example rather than clearing unrelated events in your session. Microsoft distinguishes the two cleanup operations: Unregister-Event stops the subscription, while Remove-Event deletes events already in the queue.
Closing the PowerShell session also ends its subscriptions and discards its queue. Save any results you need before cleaning up.
Troubleshooting and limits
- Nothing appears: Confirm that
$projectPathis the folder you changed, that$watcher.EnableRaisingEventsisTrue, and that you’re inspecting the same PowerShell session. Check whether a narrowFilteris excluding the test file. - Too many events: Build outputs, editors, and sync tools can generate many changes. Watch a smaller folder or use a filename filter. Duplicate-looking notifications are not necessarily a malfunction.
- An error is reported: Inspect the error message, check the folder and any network connection, and restart monitoring if needed. After an overflow, compare the actual folder contents with a known baseline; missed notifications cannot be reconstructed from the queue.
- A whole folder was moved in: Microsoft notes that moving or copying a folder into a watched location may report the folder without individual notifications for every item inside it. Inspect the folder contents if you need that detail.
- You need a durable audit trail: This session queue is a convenient diagnostic tool, not a tamper-resistant audit log or a substitute for backups. It records notifications, not file contents or the identity of the person or process responsible.
For related WindowsForum topics, explore PowerShell automation, Windows file permissions, and project backup strategies. A watcher can tell you that the kitchen got noisy; it cannot, by itself, guarantee a complete recipe for what happened.