Update to: Automated Scripting Notifications

mjones
mjones Member Posts: 176 ✭✭✭✭

Hey All,
I posted a while ago that I was looking for a way to see what scripts were run when a threshold was triggered, and what the results were. I am posting my solution here in hopes that it helps some of you to work around some of the limitations in the reporting.

For example, if a threshold fires for a DNS issue and flushing the cache fixes the problem, the following script would run and then alert you what the results were.

Script:

$txt_File_Output_Path = $Env:windir+"\temp\Atera_"+$Env:ComputerName+"Flush_DNS"+$currDate+".txt"
Start-Transcript -Path $txt_File_Output_Path ipconfig /flushdns
Write-Host "DNS Cache Flushed." Stop-Transcript $smtpServer = "mail.smtp2go.com"
$from = "script@yourdomain.com"
$to = "you@yourdomain.com"
$subject = "Script Output"
$body = "See attached files for script output."
$port = 2525
# Not actually encrypted password, just double Base64 encoded $encrypted = [Text.Encoding]::Utf8.GetString([Convert]::FromBase64String([Text.Encoding]::Utf8.GetString([Convert]::FromBase64String('Double_Base64_String_Goes_Here'))))
$smtpPassword = ConvertTo-SecureString -String $encrypted -AsPlainText -Force $smtpCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $from, $smtpPassword
$attachments = @($txt_File_Output_Path) Send-MailMessage -SmtpServer $smtpServer -From $from -To $to -Subject $subject -Body $body -Attachments $attachments -UseSsl -Port $port -Credential $smtpCredential -Encoding "utf8"


Output would be:

###########################
Windows PowerShell transcript start
Start time: 20240409143503
Username: DOMAIN\user
RunAs User: DOMAIN\user
Configuration Name:
Machine: WKS-100 (Microsoft Windows NT 10.0.22621.0)
Host Application: C:\Windows\system32\WindowsPowerShell\v1.0\PowerShell_ISE.exe
Process ID: 36632
PSVersion: 5.1.22621.2506
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.22621.2506
BuildVersion: 10.0.22621.2506
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1 ########################### Transcript started, output file is C:\Windows\temp\Atera_WKS-100_Flush_DNS_.txt Windows IP Configuration Successfully flushed the DNS Resolver Cache.
DNS Cache Flushed. ########################### Windows PowerShell transcript end
End time: 20240409143504 ###########################

Previous related posts:

Comments

  • koen
    koen Member Posts: 1 ✭✭

    This is very interesting, i will give it a try later on. Thanks @mjones

  • Sarah_from_Atera
    Sarah_from_Atera Member Posts: 93 ✭✭✭

    Hey @mjones , Sarah from Atera here.

    This is exactly what we are looking for from our Community members! Thanks for sharing your insight, hopefully it will help other Atera users moving forward.