Finding Folder Changes

by Feb 24, 2009

Compare-Object can help you monitor folder content and find changes. To monitor, first create an initial snapshot. At a later time, you can then compare the current folder content against that snapshot:

$shot1 = Dir $home
Set-Content $hometestfile1.txt 'Some content'
$shot2 = Dir $home
Compare-Object $shot1 $shot2 -syncWindow 30

This works fine for new and deleted files, but it will not show you files that changed content:

$shot1 = Dir $home
Add-Content $hometestfile1.txt 'A new line'
$shot2 = Dir $home
Compare-Object $shot1 $shot2 -syncWindow 30

By default, Compare-Object uses only the file name for comparison. To include more properties, use the -property parameter:

Compare-Object $shot1 $shot2 -syncWindow 30 -property Name, Length