Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

email if no new files in last 2 days Expand / Collapse
Author
Message
Posted Monday, July 28, 2014 1:57 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 29, 2014 7:50 AM
Points: 3, Visits: 2
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
Post #1597051
Posted Monday, July 28, 2014 2:49 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 1:45 AM
Points: 5,813, Visits: 3,734
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!!!
Post #1597066
Posted Monday, July 28, 2014 2:55 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 29, 2014 7:50 AM
Points: 3, Visits: 2
this tells me that there is a file there I want something to tell me there is not new file there
Post #1597069
Posted Monday, July 28, 2014 3:15 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 1:45 AM
Points: 5,813, Visits: 3,734
$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!!!
Post #1597081
Posted Tuesday, July 29, 2014 7:52 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 29, 2014 7:50 AM
Points: 3, Visits: 2
thanks it worked
Post #1597299
Posted Tuesday, July 29, 2014 8:35 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 1:45 AM
Points: 5,813, Visits: 3,734
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!!!
Post #1597327
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse