Level Verified

Windows Admin Login Alert Script

Detects and alerts on administrator logins within the last hour. Pair with a script-based monitor in Level to automatically generate alerts for new admin logins.

Import into Level

Problem overview

Unauthorized or unexpected administrator logins can be a major security risk, potentially indicating compromised credentials or suspicious activity. Monitoring these logins in real-time allows IT professionals and MSPs to detect potential security breaches, ensure compliance with security policies, and proactively address unauthorized access attempts before they escalate.

PowerShell 300s timeout Runs as Local system Windows
<#
This resource is provided as a convenience for Level users. We cannot 
guarantee it will work in all environments. Please test before deploying 
to your production environment. We welcome contributions to our community 
library

# Level Library
# https://level.io/library/script-windows-admin-login-alert
#>

# Define known system accounts to ignore
$SystemAccounts = @("DWM-1", "DWM-2", "DWM-3", "UMFD-0", "UMFD-1", "UMFD-2", "UMFD-3", "SYSTEM")

# Get recent successful logins (Event ID 4624) and filter for interactive/RDP logins
$Logins = Get-WinEvent -FilterHashtable @{
    LogName = 'Security'
    ID = 4624
    StartTime = (Get-Date).AddHours(-1)  # Filter for the last 1 hours
} | Where-Object {
    # Extract logon type
    $LogonType = $_.Properties[8].Value
    # Only check interactive (2) and remote desktop (10) logins
    $LogonType -eq 2 -or $LogonType -eq 10
} | ForEach-Object {
    $_.Properties[5].Value  # Extract the account name
} | Where-Object { $_ -notin $SystemAccounts } | Select-Object -Unique

# Output detected logins
Write-Host "Detected Admin Logins: $($Logins -join ', ')"
exit 0

This script scans Windows Event Logs for successful administrator logins (Event ID 4624) within the past hour, specifically filtering for interactive (local console) and remote desktop (RDP) logins. It excludes known system accounts to reduce false positives and outputs a list of detected logins. When paired with a script-based monitor in Level, this script can trigger real-time alerts whenever an admin login occurs, helping IT teams maintain strict oversight of privileged account usage.

Script

unknown node

Use cases

  • Detect unauthorized or unexpected admin logins in real-time.
  • Monitor privileged account activity to enhance security and compliance.
  • Track remote desktop access for security auditing.
  • Reduce the risk of compromised admin credentials by receiving immediate alerts.

Recommendations

  • Pair with a script-based monitor in Level to automatically trigger alerts for new admin logins.
  • Test before deploying in a production environment to ensure compatibility with your setup.
  • Adjust system account exclusions as needed to avoid false positives.
  • Regularly review logs and alerts to identify patterns of unauthorized access attempts.
  • Integrate with other security tools to automate responses to suspicious login activity.

Frequently asked questions.

How can I configure this script to trigger alerts automatically?

Use Level’s script-based monitor to run this script periodically. If any new admin logins are detected, configure the monitor to generate an alert in Level’s dashboard.

Can I modify the timeframe for detecting logins?

Yes, you can adjust (Get-Date).AddHours(-1) to a different time range, such as -2 for two hours or -30 for 30 minutes.

What if I see false positives from system accounts?

The script already excludes common system accounts, but you can customize the $SystemAccounts list to exclude additional accounts unique to your environment.

Can this script be used for compliance auditing?

Yes, this script helps track privileged account activity, which can be useful for security audits and compliance with regulations like HIPAA, PCI-DSS, and NIST.

Does this script impact system performance?

No, it queries the Windows Event Logs efficiently and should have minimal performance impact. However, always test in a controlled environment before full deployment.

Ready when you are.

No credit card. No sales call. Just sign up and start managing.