Script to check for daily backup file and email is none exist

murryc used Ask the Experts™
Need a script I can schedule daily to verify that a backup file exists on the local machine. If it doesn't exist then it needs to use blat or some similar solution to email a notification about the missing backup file. The location of the backup will be C:\VTBackups\ and the filename structure is VtDb_VT_YYYYMMDD_21_00_00.Bak, so the backup for today would have been VtDb_VT_20180828_21_00_00.Bak.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
function send-myemail 
    [String]$ToAddress = '',
    [String]$FromAddress = '',
    [String]$SmtpServer = '',
    [int]$SmtpPort = 587

  $emailParams = @{
    To = $ToAddress
    Subject = 'Backup Failure ' + $today
    Body =  'Backup File not Found'
    From = $FromAddress
    smtpserver= $SmtpServer
    Port = $SmtpPort
    Credential = $smtpcred
    #Attachments = $Attachment
  Send-MailMessage @mailparam -UseSsl
$path = 'C:\VTBackups\VtDB_VT_'
$today = get-date -Format "yyyyMMdd"
$result = get-childitem -Path ($path + $today+ "*")
if($result.count -lt 1){
  send-myemail $today

Open in new window

Top Expert 2016

asked and answered

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial