cat > troubleshooting.ps1 <
# Get-SystemErrorsAndReboots.ps1 # Function to write section headers function Write-SectionHeader($title) { Write-Host "`n===== $title =====" -ForegroundColor Cyan } # Get recent system errors Write-SectionHeader "Recent System Errors" Get-EventLog -LogName System -EntryType Error -Newest 10 | Format-Table TimeGenerated, Source, Message -AutoSize -Wrap # Get recent critical events Write-SectionHeader "Recent Critical Events" Get-EventLog -LogName System -EntryType Error -Newest 10 | Where-Object {$_.EntryType -eq "Critical"} | Format-Table TimeGenerated, Source, Message -AutoSize -Wrap # Get recent unexpected shutdowns Write-SectionHeader "Recent Unexpected Shutdowns" Get-EventLog -LogName System -InstanceId 41 -Newest 5 | Format-Table TimeGenerated, Message -AutoSize -Wrap # Get recent reboot events Write-SectionHeader "Recent Reboot Events" Get-WinEvent -FilterHashtable @{LogName='System'; ID=1074,6006,6005,6008} -MaxEvents 10 | Format-Table TimeCreated, Id, Message -AutoSize -Wrap # Get last boot time Write-SectionHeader "Last Boot Time" Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object LastBootUpTime # Get system uptime Write-SectionHeader "System Uptime" $bootuptime = (Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime $uptime = (Get-Date) - $bootuptime Write-Host "Days: $($uptime.Days), Hours: $($uptime.Hours), Minutes: $($uptime.Minutes)" # Get Windows Update history Write-SectionHeader "Recent Windows Updates" Get-HotFix | Sort-Object -Property InstalledOn -Descending | Select-Object -First 10 | Format-Table HotFixID, Description, InstalledOn -AutoSize # Pause to keep the console window open Write-Host "`nPress any key to exit..." $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")