The Script
Key Features
- Filters by IP Address: Searches for events where the IP address matches the specified value.
- Time Range: Limits results to events that occurred in the last 7 days using the
TimeCreated
property. - CSV Output: Saves event details (timestamp, ID, and message) to a specified CSV file.
How to Use It
- Replace
10.1.1.1
with the target IP address. - Save the script to a
.ps1
file or run it directly in PowerShell with administrator privileges. - Locate the output file (
C:\SecurityEvents_Last7Days.csv
) for review.
Script Workflow
- Input Definition: The
$ipaddress
variable holds the IP address, and$outputFile
specifies the CSV file location. - Time Range Setup:
$startDate
is calculated as 7 days prior to the current date. - Event Filtering:
Get-WinEvent
retrieves log entries matching the IP address.Where-Object
ensures only events from the past 7 days are included. - Data Export: Selected details are saved to the CSV file for analysis.
Practical Applications
- Security Monitoring: Quickly identify events tied to suspicious IP activity.
- Incident Investigation: Focus on recent logs for faster issue resolution.
- Data Analysis: Exported CSV files can be reviewed in Excel or other tools.
Conclusion
This script is a concise, efficient way to analyze recent security events related to a specific IP address. Adjust the IP and time range as needed for your specific use case, and use the exported data to inform your network security actions.