Listen to this Post

Introduction
Managing Windows Event Logs efficiently in Microsoft Sentinel or DefenderXDR can be costly and redundant if logs are not properly filtered. Sergio Albea presents a zero-cost solution using Scheduled Tasks and PowerShell to detect critical events and trigger DefenderXDR incidents—without ingesting unnecessary data. This method is ideal for detecting ransomware and other threats while keeping costs low.
Learning Objectives
- Learn how to use PowerShell and Scheduled Tasks to monitor Windows Event Logs.
- Understand how to trigger DefenderXDR incidents without log ingestion.
- Implement custom event triggers for advanced threat detection.
You Should Know
- Setting Up a Scheduled Task for Event Log Monitoring
PowerShell Command:
$Action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File C:\Scripts\MonitorEvents.ps1" $Trigger = New-ScheduledTaskTrigger -AtStartup Register-ScheduledTask -TaskName "MonitorSecurityEvents" -Action $Action -Trigger $Trigger -User "SYSTEM"
Step-by-Step Guide:
- Create a PowerShell script (
MonitorEvents.ps1) to query specific Event IDs (e.g., 4624 for logon events). - Use `Get-WinEvent` to filter logs and trigger DefenderXDR alerts via API.
- Schedule the script to run at system startup or at intervals.
2. Filtering Event Logs with PowerShell
PowerShell Command:
Get-WinEvent -FilterHashtable @{LogName='Security'; ID=4624, 4625} | Export-CSV "C:\Logs\SecurityEvents.csv"
Step-by-Step Guide:
- Use `Get-WinEvent` with a hashtable filter to extract only relevant events.
- Export logs to a CSV for analysis or forward them to DefenderXDR.
- Combine with conditional logic to trigger alerts for suspicious activity.
3. Triggering DefenderXDR Incidents via API
PowerShell Command:
$Body = @{
"EventID" = "4625"
"Description" = "Multiple failed logins detected"
} | ConvertTo-Json
Invoke-RestMethod -Uri "https://api.securitycenter.microsoft.com/api/alerts" -Method Post -Body $Body -Headers @{Authorization = "Bearer $Token"}
Step-by-Step Guide:
1. Generate an API token for DefenderXDR.
2. Format the alert payload in JSON.
- Use `Invoke-RestMethod` to send the alert directly to DefenderXDR.
4. Detecting Ransomware Patterns with Event Correlation
PowerShell Command:
$Events = Get-WinEvent -FilterHashtable @{LogName='Security'; ID=4663} | Where-Object { $_.Message -like "encrypt" }
if ($Events.Count -gt 5) {
Trigger DefenderXDR alert
}
Step-by-Step Guide:
- Scan for Event ID 4663 (file access) with keywords like “encrypt.”
- If multiple events occur in a short time, trigger an incident.
3. Adjust thresholds based on your environment’s baseline.
5. Automating Log Cleanup to Reduce Storage Costs
PowerShell Command:
wevtutil.exe cl Security
Step-by-Step Guide:
1. Use `wevtutil` to clear old logs periodically.
- Schedule this command to run during off-peak hours.
- Retain only logs necessary for compliance or investigations.
What Undercode Say
- Key Takeaway 1: This method reduces SIEM costs by avoiding unnecessary log ingestion while maintaining threat detection.
- Key Takeaway 2: Custom event triggers allow for tailored detection of advanced threats like ransomware.
Analysis:
By leveraging PowerShell and Scheduled Tasks, security teams can maintain high visibility without inflating cloud costs. This approach is particularly useful for organizations with limited budgets but high security requirements. Future integrations with AI-driven anomaly detection could further enhance this model.
Prediction
As cloud security costs rise, lightweight, script-based monitoring will become a standard for cost-conscious enterprises. AI-powered event correlation may soon automate much of this process, reducing manual effort while improving accuracy.
For further insights on AI-driven security, check out Sergio Albea’s work or explore upcoming webinars like AI for Connected Devices.
🎯Let’s Practice For Free:
IT/Security Reporter URL:
Reported By: Sergioalbea Microsoftsentinel – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅


