I'm trying to figure out a good way to incorporate some powershell into a process that I am currently taking care of manually though the use of another application bundled with a MFC that was recently purchased. This MFC will create PDF's of incoming faxes and will save them to a network drive. Great feature, but requires software to configure it and monitor it. This particular software doesn't work well in a multi-user environment so I thought I could use Powershell to monitor the network share, and alert the user (or users) who is in charge of all incoming faxes without having to use this application that came bundled with the MFC.
So I did a little googling and found a couple of examples that I tried to piece together but I am starting to wonder if I am making this more difficult than it has to be.....I know there's probably a pre-made app out there but I like to try to do as much with Powershell as I can, helps me learn it.
TLDR
Here's what I want to do. I want to have this script run ever 15 minutes or even continuously to monitor the Fax folder I have setup. When a file is created in said directory, I want to trigger and log an event ID which will be polled by a scheduled task I will create later. This scheduled task will look for the ID, and if found, will send an email message to the user(s) that a new fax has arrived.
Current code:
#**************************************Alert_New_Fax.ps1******************************# #************************************|Script by: Bill Kindle|*************************# #***********************************|Script created: 09/10/13|************************# #Original Source: # # http:// # # http:/dereknewton.com/ 2011/ 05/ monitoring-file-system-changes-with-powershell / # #=====================================================================================# #Purpose: #This script was pieced together using the above source and customized to suite a #specific need I have for alerting a user that a new fax has been recieved. This script #watches a directory and creates an event ID which Task Scheduler is set to watch for. #When the event ID is detected by Task Scheduler, it sends the email to the specified #user as a separate process from this script. #=====================================================================================# #www.petri.co.il/ use-powershell-to-create-custom-log-events.htm # # # $searchPath = "C:\DATA\FAXES" # # $watcher = New-Object System.IO.FileSystemWatcher $watcher.Path = $searchPath $watcher.IncludeSubdirectories = $false $watcher.EnableRaisingEvents = $true # # #$changed = Register-ObjectEvent $watcher "Changed" -Action { # write-host "Changed: $($eventArgs.FullPath)" #} $created = Register-ObjectEvent $watcher "Created" -Action { Write-EventLog Application -source Powershell -EventId 54321 -Message "A new fax has been received." } #$deleted = Register-ObjectEvent $watcher "Deleted" -Action { # write-host "Deleted: $($eventArgs.FullPath)" #} #$renamed = Register-ObjectEvent $watcher "Renamed" -Action { # write-host "Renamed: $($eventArgs.FullPath)" #} # #