So, I used the below script.
Prerequisites are that the refresh script will write the log to a shared location accessible from a Prod Server.
$date = Get-Date -Format d $dir = "\\xxxxx\g$\QARefreshLogs" $recipient = "xxxxxx" $smtpserver = "xxxxxxx" $smtpport = "xx" $smtp = new-object Net.Mail.SmtpClient($smtpServer) $msg = new-object Net.Mail.MailMessage $msg.From = "xxxxxxxxxx" $msg.To.Add($recipient) ---Retrieving the latest file $latest = Get-ChildItem -Path $dir | Sort-Object LastAccessTime -Descending | Where-Object {$_.Name -ilike "<db_name>_refresh_log_*"} | Select-Object -First 1 $LatestRefreshLog = $latest.Name $LatestRefreshLogDate = $latest.LastWriteTime.ToString('M/dd/yyyy') --Validating if the log file generated today? if (($LatestRefreshLogDate) -notmatch $date) { #Write-Host "WARNING: There is no today's restore log file!" $msg.Subject = "SQLServer QA Refresh Status" $msg.Body = "QA MSSQL DB refresh is having issues.Please validate." $smtp.Send($msg) } else { --Validating if refresh is success or not? If(Get-Content -Path $dir\$LatestRefreshLog | %{$_ -match "RESTORE DATABASE successfully processed"}) { #Write-Host "The latest restore log file is $LatestRefreshLog" $msg.Subject = "SQLServer QA Refresh Status" $msg.Body = "QA DB is refreshed successfully." $smtp.Send($msg) } else { #Write-Host "The latest restore log file is $LatestRefreshLog" $msg.Subject = "SQLServer QA Refresh Status" $msg.Body = "QA DB refresh is having issues.Restore failed." $smtp.Send($msg) } }
This may not be an optimal script. It served my purpose....thanks for all your inputs. This script could be helpful to others, have a PoSh time!!!