July 28, 2014 at 1:57 pm
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
July 28, 2014 at 2:49 pm
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!!!
July 28, 2014 at 2:55 pm
this tells me that there is a file there I want something to tell me there is not new file there
July 28, 2014 at 3:15 pm
$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!!!
July 29, 2014 at 7:52 am
thanks it worked
July 29, 2014 at 8:35 am
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