Last active
November 3, 2015 19:37
-
-
Save csandfeld/96d4785ec896ecca4538 to your computer and use it in GitHub Desktop.
Script to check if log file created today exist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Folder where logfiles are stored | |
$Path = 'C:\TEMP' | |
# Filename pattern for regex match operator (<guid>.log) | |
$Pattern = '^.{8}-.{4}-.{4}-.{4}-.{12}\.log$' | |
$From = 'from@example.com' | |
$To = 'to@example.com' | |
$SmtpServer = 'smtpserver.domain.local' | |
$Subject = 'Todays log file was not found' | |
# If number of files in path, with name matching specified pattern, and created today = 0 | |
if ( (Get-ChildItem -Path $Path | Where-Object { ($_.Name -match $Pattern) -and ($_.CreationTime.Date -eq (Get-Date).Date) }).Count -eq 0 ) { | |
Send-MailMessage -From $From -To $To -SmtpServer $SmtpServer -Subject $Subject | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment