Newbie PS Question - Revising question as I think I am about 95% to my solution based on community help so far.
My PS script is querying a .log file and if it matches a -15 minute rule as well as a text selection, it pulls all of the records I want. Which is fantastic.
The issue I have is that I need to email the results to me if those conditions are met. As you can see in the code below, i have the mail setup, but when it comes to the body of the email I get no data. I have tried setting Body = $body but it breaks. Any suggestions on how to get this sorted?
Current Code:
$qtime = Get-Date (Get-Date).AddMinutes(-15) -Format 'yyyyMMddHHmm'
$srch = [regex]::Escape('Licensing: no speech license available for the feature')
$SEL = Select-String -Path C:ProgramDataNuanceEnterprisesystemdiagnosticLogs
rs.log -Pattern "Licensing: no speech license available for the feature"
if ($SEL -ne $null)
{
$body = Get-Content C:ProgramDataNuanceEnterprisesystemdiagnosticLogs
rs.log | Where { $_ -gt $qtime -and $_ -match $srch}
# Send-MailMessage -From '[email protected]' -To '[email protected]' -Subject 'TTS License Error Detected on ServerA' -SmtpServer 'smtp.domain.com' -body $body
}
else
{
## Do Nothing
}
Thanks in advance -
J