Finding Folder Changes

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 $home\testfile1.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 $home\testfile1.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

Posted Feb 24 2009, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.