Document daily report, deploy marker, SkipScheduledTaskMaintenance, and legacy watchdog scripts. Add full English translation.
5.5 KiB
RDP Login Monitor
PowerShell toolkit for monitoring Windows logons with Telegram notifications.
Recommended layout
- Installation root:
C:\ProgramData\RDP-login-monitor\. - Main script:
Login_Monitor.ps1— Security log4624/4625(behavior depends on OS type: workstation vs server/domain controller), optional Remote Connection Manager1149when the log is available (often useful for RDP-enabled workstations), RD Gateway events302/303when the gateway role/log is present, daily report to Telegram (active sessions viaquser), heartbeat, log rotation, Telegram alerts. - Scheduled tasks: run
Login_Monitor.ps1 -InstallTasksto register:RDP-Login-Monitor(main monitor),RDP-Login-Monitor-Watchdog(process health check every 5 minutes).
- Domain delivery and upgrades:
Deploy-LoginMonitor.ps1+version.txton a share such asNETLOGON. After a successful deploy, the startup Telegram message may include an update note (filedeploy_last_update.txtnext to logs). - Full deploy/GPO guidance: DEPLOY.md.
Encrypt-DpapiForRdpMonitor.ps1— optional helper to prepare DPAPI-protected Base64 for the bot token / chat id.
Notable behavior
.ps1encoding:.editorconfigand.gitattributesencourage*.ps1as UTF-8 with BOM and CRLF, reducing mojibake and PowerShell parse issues.- Log encoding:
login_monitor.log/watchdog.logare written as UTF-8 with BOM (BOM is applied to existing files if missing) so viewers like FAR Manager do not mis-detect encoding. auditpolon Russian Windows: auditing checks use theВход/выходcategory andВход в систему/Выход из системыsubcategories (expectУспех и сбой), avoiding errors such as0x00000057when English names likeLogonare absent on a localized OS.- Stability:
auditpolis invoked viacmd.exewith merged stdout/stderr so$ErrorActionPreference = 'Stop'does not abort on stderr-only output.
1) Preparation
- Create the install folder:
C:\ProgramData\RDP-login-monitor\
- Copy at least:
Login_Monitor.ps1- (for domain rollout on a share)
Deploy-LoginMonitor.ps1andversion.txt.
- Edit
Login_Monitor.ps1and set the bot token / chat:$TelegramBotTokenor$TelegramBotTokenProtectedB64$TelegramChatIDor$TelegramChatIDProtectedB64
- Run elevated (Security log access and task registration).
- Logs and auxiliary files:
C:\ProgramData\RDP-login-monitor\Logs\
2) Manual run
Use this to validate startup/logic without registering scheduled tasks.
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\ProgramData\RDP-login-monitor\Login_Monitor.ps1"
The monitor keeps running in the session until you stop it (for example Ctrl+C).
3) Task Scheduler
You do not need to create tasks manually in the GUI.
Run:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\ProgramData\RDP-login-monitor\Login_Monitor.ps1" -InstallTasks
The script registers RDP-Login-Monitor and RDP-Login-Monitor-Watchdog, then triggers an immediate first run.
For domain deployment from a share you do not configure the scheduler on clients by hand — use Deploy-LoginMonitor.ps1 (see DEPLOY.md).
4) Post-install checks
- Logs:
C:\ProgramData\RDP-login-monitor\Logs\login_monitor.logC:\ProgramData\RDP-login-monitor\Logs\watchdog.log
- Heartbeat:
C:\ProgramData\RDP-login-monitor\Logs\last_heartbeat.txtupdates on$HeartbeatInterval(hourly by default).
- Daily report: after the first daily window (default 09:00, controlled by
$DailyReportHour/$DailyReportMinuteinLogin_Monitor.ps1), Telegram receives aqusersummary; last run marker:Logs\last_daily_report.txt. - Startup Telegram message: with RD Session Host (or broader RDS session components, not gateway-only) you get the RDS/RDP session-host line; when the RD Gateway log is available you get a separate line about connections to internal targets through the gateway (302/303). A gateway-only node does not duplicate the “session host” wording.
5) Automatic restart on failure
-Watchdog inside Login_Monitor.ps1:
- looks for
powershell.exe/pwsh.exewhose command line referencesLogin_Monitor.ps1; - if the main monitor is missing, starts it;
- if the monitor is already running, does not spawn a second instance.
6) Extra parameters and other repo files
-SkipScheduledTaskMaintenance: during normal monitor startup, skip verification/recreation of scheduled tasks (if you manage tasks only via-InstallTasksor manually).Install-DeployScheduledTask.ps1— helper to runDeploy-LoginMonitor.ps1from a share on a schedule (see DEPLOY.md).Watchdog_RDP_Monitor.ps1andInstall-ScheduledTasks.ps1— alternate layout with a separate watchdog script and default paths underD:\Soft. For new installs, prefer the built-in-WatchdoginLogin_Monitor.ps1and tasksRDP-Login-Monitor/RDP-Login-Monitor-Watchdog.
Keywords (for discovery)
rdp, rd-gateway, rdp-gateway, rds, remote-desktop, windows-security-log, eventlog, event-id-4624, event-id-4625, event-id-302, event-id-303, powershell, telegram-bot, watchdog, gpo, netlogon, domain-deployment, windows-server, monitoring