Advertisements

Send an email alert if a file is created that contains a certain string

So, download yourself the File Watcher Simple

http://sourceforge.net/projects/fwutilities/

Click New

Give the Daemon a name, and have it watch say the c:\Test

I only needed ‘File or folder created’ checked and the event is File name

Under process Tab I just type powershell

Check box the ‘Start process when file system change is detected’

And I used c:\test as the process working directory

Under Process arguments:

file watcher simple

c:\test.ps1 %1

And Process arguments file name escape string:

%1

and check box the Use file name as argument

So what does our little test.ps1 powershell file look like

$FileName=$args[0]
$SearchString = “string”
$PSEmailServer = “mailserver”
$Sel = select-string -pattern $SearchString -path $FileName
If ($Sel -eq $null)
{
echo “Not Found”
}
Else
{
echo “Found”
Send-MailMessage -to “email@email.com” -from “<somehwere@somewhere.com>” -Subject “found” -body “found”
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: