Issue 1: How to compare two directories?

Resolution: Take a snapshot of the original directory, wait a certain amount of time to take a second snapshot, and then compare the two. **Reference:** See the article, Finding New Files and Folders.http://powershell.com/cs/blogs/tobias/archive/2009/01/09/tipps-amp-tricks-using-compare-object.aspx


Issue 2: How to get the output of Compare-Object so that it can be emailed to the user?</p>

Resolution: Append the output to a text file. I used the ΓÇôPassThru parameter and >$report.txt to append the output to a text file.

Reference: http://technet.microsoft.com/en-us/library/dd347568.aspx

Issue 3: How to send an email through powershell?

Resolution: Google search for ΓÇ£Send smtp email with powershellΓÇ¥ (see script for syntax to send an email)

Notes: As long as you are sending within the iit.edu domain, you do not need to worry about credentials. In addition, it does not matter what email address you type into the ΓÇ£from ΓÇ£ field, as it is not checked to see if it is a valid email address or not.

Issue 4: How to setup the script so that it only emails the user when something has changed in the directory?

Resolution: Setup an IF statement. The IF statement in the script says that if the report.txt file is greater than 0kb, call the function ΓÇ£sendEmailΓÇ¥

Reference: http://www.powershellpro.com/powershell-email-alerts/210/

Issue 5:  How to put the script in a loop and have it wait a certain amount of time before taking the snapshot again?

Resolution: use the start-sleep Cmdlet

Reference: http://technet.microsoft.com/en-us/library/ee177002.aspx

The script is provided below:

## This script can monitor multiple directories
## Change the information below as needed</p>

## directory to monitor
## change as necessary
$dir="x:\folder1","x:\folder2","x:\folder3"

## Generated report of new files
## make sure the location of the report file is not in the same location as the directory you a monitoring
$report="X:\report.txt"

## Email portion, change as necessary
$EmailTo="Firstname Lastname <username@domain.com>"
$EmailSubject="Subject Goes Here"
$EmailBody="Body Goes Here"
$EmailFrom="Firstname Lastname <username@domain.com>"
$EmailSMTPServer="mail.domain.com"

## =========================================================
## ======== PLEASE DO NOT EDIT SCRIPT BELOW ================
## =========================================================

$val=1

while($val -eq 1){

$shot2 = Dir $dir

Compare-Object $shot1 $shot2 -PassThru >$report

function sendEmail{
send-mailmessage -from $EmailFrom -to $EmailTo -subject $EmailSubject -body $EmailBody -Attachments "$report" -priority High -dno onSuccess, onFailure -smtpServer $EmailSMTPServer
}

$File = Get-ChildItem $report
if ($File.Length -gt 0) {sendEmail}

$shot1 = Dir $dir

# this will pause the script for 60 seconds, change as necessary
Start-Sleep -s 60

}

</pre>