Script - Sending an email if file modified time is greater than 60 minutes


I am involved with a radio station that has its national hourly news sent from another radio station via FTP to our local server every hour between 6am-6pm. Sometimes older news bulletins are being replayed because of technical problems in getting the bulletin to us via FTP from the other radio station.

I was hoping somebody might be able to help me out with a PS script that performs the following tasks.

  1. Checks the time stamp on the news file on our server (g:\audio\nrn\news.mp3)
  2. If the current time is greater than 60 minutes from the modified time on the news.mp3 file then send an email to the Program Director advising that the news did not update, then close script.
  3. If the current time is less than 60 minutes from the modified time on the news.mp3 file (means an updated bulletin exists) do nothing then close script.

I guess I could setup a task in Windows to run the PS script every day between 6am-6pm.

I would appreciate any help.


replace (less than sign) and (greater than sign) with the corresponding single characters…

#region Input
$FileName        = 'g:\audio\nrn\news.mp3'
$EmailSender     = 'Hourly news file monitor (less than sign) than sign)'
$EmailRecipients = @( # Add recipients email addresses below:
    'Sam Boutros (less than sign) than sign)'
$SMTPServer      = ''

#region Process
try {
    $FileTimeStamp = (Get-Item -Path $FileName -ErrorAction Stop).LastWriteTime
} catch {
    throw $_
if ((Get-Date).AddHours(-1) -gt $FileTimeStamp) {
    $Email = "File '$FileName' time stamp '$FileTimeStamp' is older than 60 minutes"
    try { 
        Send-MailMessage -From $EmailSender -To $EmailRecipients -Body $Email -SmtpServer $SMTPServer -Subject $Email -Priority High -ErrorAction Stop
        "Email sent successfully"
    } catch {
        throw $_
} else {
    "File '$FileName' time stamp '$FileTimeStamp' is NOT older than 60 minutes"