Skip to content

Instantly share code, notes, and snippets.

@csandfeld
Last active November 3, 2015 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csandfeld/96d4785ec896ecca4538 to your computer and use it in GitHub Desktop.
Save csandfeld/96d4785ec896ecca4538 to your computer and use it in GitHub Desktop.
Script to check if log file created today exist
# 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