-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWired-AutoConfig-Operational-Logs.ps1
More file actions
33 lines (25 loc) · 1.06 KB
/
Wired-AutoConfig-Operational-Logs.ps1
File metadata and controls
33 lines (25 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# List the last 24 hours logs for Wired-AutoConfig Operational. This will output to console and save logs to $outputDir location
$LastHours = 24
# Define the log name and output directory
$logName = 'Microsoft-Windows-Wired-AutoConfig/Operational'
$outputDir = 'C:\Logs\Wired-AutoConfig'
# Create the output directory if it doesn't exist
if (-not (Test-Path $outputDir)) {
New-Item -Path $outputDir -ItemType Directory -Force
}
# Calculate the time 24 hours ago
$startTime = (Get-Date).AddHours(-$LastHours)
# Get the logs from the last 24 hours
$events = Get-WinEvent -LogName $logName | Where-Object { $_.TimeCreated -ge $startTime }
# Output to console
$events |
Select-Object TimeCreated, Id, LevelDisplayName, Message |
Format-List
# Create a timestamped file
$timestamp = Get-Date -Format 'yyyy-MM-dd_HH-mm-ss'
$outputFile = Join-Path $outputDir "WiredAutoConfigLogs_$timestamp.txt"
# Save to file
$events |
Select-Object TimeCreated, Id, LevelDisplayName, Message |
Out-File -FilePath $outputFile -Encoding UTF8
Write-Host "`nLogs saved to: $outputFile"