email if no new files in last 2 days

  • I have this code that works great if there is a new file in the last 23 hours. how can I adjust it that if there is no new files in the last 2 days it will send me an email

    Param (

    [string]$Path = "d:shared\ftpimport\failed",

    [string]$SMTPServer = "mail.optonline.net",

    [string]$From = "SFTPAlert@yahoo.com",

    [string]$To = "morris@yahoo.com",

    [string]$Subject = "New File Failed to upload"

    )

    $SMTPMessage = @{

    To = $To

    From = $From

    Subject = "$Subject at $Path"

    Smtpserver = $SMTPServer

    }

    $File = Get-ChildItem $Path | Where { $_.LastWriteTime -ge [datetime]::Now.Addhours(-23) }

    If ($File)

    {$SMTPBody = "`nThe following files have recently been added/changed:`n`n"

    $File | ForEach { $SMTPBody += "$($_.FullName)`n" }

    Send-MailMessage @SMTPMessage -Body $SMTPBody

  • Am I missing something or do you need to change -23 to -48 in the call to AddHours.

    Or did you want it based on date?

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

  • this tells me that there is a file there I want something to tell me there is not new file there

  • $File = Get-ChildItem $Path | Where { $_.LastWriteTime -ge [datetime]::Now.Addhours(-48) }

    If (!$File)

    {

    # No file changed in 48 hours

    }

    I hope that helps.

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

  • thanks it worked

  • Glad to have helped.

    Please could you mark the appropriate post as the solution to aid future readers of this thread Thanks.

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply