MSP Programs & Scripts Code
Programs and PowerShell Scripts for MSP/RMM Admins
Brought to you by:
theitguys
# # Author: Josh German # Date: 2019-01-24 # Via: NinjaRMM Colab Slack Group # ## This is your SendGrid API key $SendGridAPIKey = '<SECRETAPIKEY>' ## This is the email you will send to $RecipientEmail = 'tech@aplg8.net' ## This is the email you are sending from (this is also the reply email address) $SenderEmail = 'ninjarmm@aplg8.net' ## This is the email subject line, and you can use PowerShell variables to make this more descriptive $EmailSubject = "Bluescreen logs from ${Env:ComputerName}" ## Create a temporary directory for SYSTEM (basis of our scripts) $TEMPDIR = "${Env:SystemDrive}\System" If (! (Test-Path -PathType Container $TEMPDIR) ) { New-Item -ItemType Directory -Force -Path $TEMPDIR | Out-Null } ## Create a temporary directory to store the export .dmp files $TEMPDIR = "${Env:SystemDrive}\System\bluescreen logs" If (! (Test-Path -PathType Container $TEMPDIR) ) { New-Item -ItemType Directory -Force -Path $TEMPDIR | Out-Null } ## Gather the log data foreach ( $log in $LogsToInterrogate ) { ## Get the blue screen log files Copy-Item -Path "${Env:SystemDrive}\Windows\Minidump\*.dmp" -Destination "${Env:SystemDrive}\System\bluescreen logs" } ## This is a multi-line string where you can add additional information to the body of the email $EmailBody = @(" Attached are the mini dump logs from the following computer: ${Env:ComputerName}") ## Create the mail message object $SMTPMessage = New-Object System.Net.Mail.MailMessage($SenderEmail, $RecipientEmail, $EmailSubject, $EmailBody) ## Get all of the files in $TEMPDIR and attach them to the email ## There should be one EVTX file for each log we gathered events from Get-ChildItem -Path $TEMPDIR | Foreach-Object { $SMTPMessage.Attachments.Add((New-Object System.Net.Mail.Attachment($_.FullName))) } ## Create the connection to the SMTP relay and send the message $SMTPClient = New-Object Net.Mail.SmtpClient('smtp.sendgrid.com', 25) $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("apikey", "${SendGridAPIKey}"); $SMTPClient.Send($SMTPMessage)