Skip to content

Instantly share code, notes, and snippets.

@D4R4
Created July 30, 2020 22:29
Show Gist options
  • Save D4R4/213eabb5412a29c93b226730a2904da3 to your computer and use it in GitHub Desktop.
Save D4R4/213eabb5412a29c93b226730a2904da3 to your computer and use it in GitHub Desktop.
Send SMS on RDP login - using TextMagic Email2SMS service, Event Viewer
Logon refers to an RDP logon to the system, an event that appears after a user has been successfully authenticated. It is an event with the EventID 21 (Remote Desktop Services: Session logon succeeded). This events are located in the “Applications and Services Logs -> Microsoft -> Windows -> TerminalServices-LocalSessionManager -> Operational”. As you can see, here you can find the ID of a user RDP session — Session ID.
Find the corresponding Even Log, right click, select "Attach Task to this event"
Launch “Event Viewer” and find the event you created in Step 1. It should be located toward the top of the “Windows Logs\Application” Log. Once found, right‐click on the event and select “Attach Task to This Event…” then use the defaults for the first couple screens of the wizard.
Create Powershell scripts C:\scirpts\send_sms.ps1 :
$SMTP_USERNAME = "[email protected]"
$SMTP_PASSWORD = "123123"
$EmailFrom = "[email protected]"
$EmailTo = "[email protected]"
$Subject = "RDP LOGIN TO DC1"
$Body = "RDP LOGIN TO DC1"
$SMTPServer = "smtp.office365.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("$SMTP_USERNAME", "$SMTP_PASSWORD");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
Create a task to “Start a Program” with the following parameters:
Program/script: PowerShell.exe
Add arguments: .\send_sms.ps1
Start in ﴾you might need to create this directory or alter the steps to use a directory of your choice﴿: C:\scirpts\
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment