<# .SYNOPSIS Generates a Windows system and maintenance report. .DESCRIPTION Dependency-free, non-GUI Windows inventory and diagnostics script. It collects: - OS, BIOS, motherboard, CPU, RAM, GPU - Disks, free space, physical disk health - Installed desktop programs and AppX packages - Startup programs, Run registry entries, startup folders - Services and stopped automatic services - Drivers and problem devices - Windows hotfixes - Defender and Firewall status - Network adapters, IP/DNS config, listening TCP ports - Power plan and battery info - Scheduled tasks - Top processes by memory - Recent System/Application event log errors - DISM component-store health - SFC verify-only status The script is intended to be READ-ONLY. It does not repair, uninstall, disable, delete, or modify system settings. .PARAMETER OutputDirectory Directory in which to write the report. Default: current working directory. .PARAMETER EventLogDays Number of days of System/Application errors to include. Default: 7. .PARAMETER MaxEventErrors Maximum number of errors to include from each event log. Default: 100. .PARAMETER InstallCommand Creates a winreport.cmd launcher next to this script. If the script folder is on PATH, you can then run: winreport .EXAMPLE .\WindowsMaintenanceReport.ps1 .EXAMPLE .\WindowsMaintenanceReport.ps1 -OutputDirectory C:\Temp .EXAMPLE .\WindowsMaintenanceReport.ps1 -EventLogDays 30 -MaxEventErrors 250 .EXAMPLE powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\WindowsMaintenanceReport.ps1 .EXAMPLE .\WindowsMaintenanceReport.ps1 -InstallCommand .NOTES Recommended: run as Administrator for the most complete output. If execution policy blocks the script, use: powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\WindowsMaintenanceReport.ps1 To call "winreport" from anywhere: 1. Put this script in a permanent folder, e.g. C:\Tools\WinReport 2. Run: .\WindowsMaintenanceReport.ps1 -InstallCommand 3. Add that folder to PATH 4. Then use: winreport #> [CmdletBinding()] param( [string]$OutputDirectory = (Get-Location).Path, [ValidateRange(1, 3650)] [int]$EventLogDays = 7, [ValidateRange(1, 5000)] [int]$MaxEventErrors = 100, [switch]$InstallCommand ) $ErrorActionPreference = 'Continue' function Test-IsAdministrator { try { $identity = [Security.Principal.WindowsIdentity]::GetCurrent() $principal = New-Object Security.Principal.WindowsPrincipal($identity) return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) } catch { return $false } } function Write-Section { param( [Parameter(Mandatory)] [System.IO.StreamWriter]$Writer, [Parameter(Mandatory)] [string]$Title, [Parameter(Mandatory)] [scriptblock]$Script ) $Writer.WriteLine() $Writer.WriteLine(('=' * 80)) $Writer.WriteLine($Title) $Writer.WriteLine(('=' * 80)) try { $result = & $Script 2>&1 | Out-String -Width 240 if ([string]::IsNullOrWhiteSpace($result)) { $Writer.WriteLine('(no output)') } else { $Writer.WriteLine($result.TrimEnd()) } } catch { $Writer.WriteLine("ERROR: $($_.Exception.Message)") } } function Install-WinReportCommand { $scriptPath = $MyInvocation.PSCommandPath if (-not $scriptPath) { throw 'Unable to determine current script path.' } $scriptDir = Split-Path -Parent $scriptPath $cmdPath = Join-Path $scriptDir 'winreport.cmd' $scriptName = Split-Path -Leaf $scriptPath $cmd = @" @echo off powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0$scriptName" %* "@ Set-Content -LiteralPath $cmdPath -Value $cmd -Encoding ASCII Write-Host "Created launcher:" Write-Host " $cmdPath" Write-Host Write-Host "If this folder is on PATH, you can run:" Write-Host " winreport" } if ($InstallCommand) { Install-WinReportCommand exit 0 } if (-not (Test-Path -LiteralPath $OutputDirectory)) { New-Item -ItemType Directory -Path $OutputDirectory -Force | Out-Null } $timestamp = Get-Date -Format 'yyyyMMdd_HHmmss' $computerName = $env:COMPUTERNAME $reportPath = Join-Path $OutputDirectory "windows_system_report_${computerName}_${timestamp}.txt" $utf8NoBom = New-Object System.Text.UTF8Encoding($false) $writer = New-Object System.IO.StreamWriter($reportPath, $false, $utf8NoBom) try { $writer.WriteLine('WINDOWS SYSTEM / MAINTENANCE REPORT') $writer.WriteLine("Generated: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss K')") $writer.WriteLine("Computer: $computerName") $writer.WriteLine("User: $env:USERNAME") $writer.WriteLine("Administrator: $(Test-IsAdministrator)") $writer.WriteLine("PowerShell: $($PSVersionTable.PSVersion)") $writer.WriteLine("Event log days: $EventLogDays") Write-Section $writer 'OPERATING SYSTEM / COMPUTER / BIOS' { Get-CimInstance Win32_OperatingSystem | Select-Object Caption, Version, BuildNumber, OSArchitecture, InstallDate, LastBootUpTime, LocalDateTime, @{N='TotalMemoryGB';E={[math]::Round($_.TotalVisibleMemorySize / 1MB, 2)}}, @{N='FreeMemoryGB';E={[math]::Round($_.FreePhysicalMemory / 1MB, 2)}} | Format-List Get-CimInstance Win32_ComputerSystem | Select-Object Manufacturer, Model, SystemType, @{N='TotalPhysicalMemoryGB';E={[math]::Round($_.TotalPhysicalMemory / 1GB, 2)}}, Domain, PartOfDomain | Format-List Get-CimInstance Win32_BIOS | Select-Object Manufacturer, Name, SMBIOSBIOSVersion, ReleaseDate, SerialNumber | Format-List } Write-Section $writer 'UPTIME' { $os = Get-CimInstance Win32_OperatingSystem $uptime = (Get-Date) - $os.LastBootUpTime [PSCustomObject]@{ LastBoot = $os.LastBootUpTime Days = $uptime.Days Hours = $uptime.Hours Minutes = $uptime.Minutes } | Format-List } Write-Section $writer 'CPU' { Get-CimInstance Win32_Processor | Select-Object Name, Manufacturer, NumberOfCores, NumberOfLogicalProcessors, MaxClockSpeed, CurrentClockSpeed, LoadPercentage | Format-List } Write-Section $writer 'MEMORY MODULES' { Get-CimInstance Win32_PhysicalMemory | Select-Object BankLabel, DeviceLocator, @{N='CapacityGB';E={[math]::Round($_.Capacity / 1GB, 2)}}, Speed, ConfiguredClockSpeed, Manufacturer, PartNumber | Format-Table -AutoSize } Write-Section $writer 'MOTHERBOARD' { Get-CimInstance Win32_BaseBoard | Select-Object Manufacturer, Product, Version, SerialNumber | Format-List } Write-Section $writer 'GPU / DISPLAY ADAPTERS' { Get-CimInstance Win32_VideoController | Select-Object Name, DriverVersion, @{N='VRAM_GB';E={ if ($_.AdapterRAM) { [math]::Round($_.AdapterRAM / 1GB, 2) } else { $null } }}, VideoModeDescription | Format-Table -AutoSize } Write-Section $writer 'LOGICAL DISKS / FREE SPACE' { Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" | Select-Object DeviceID, VolumeName, FileSystem, @{N='SizeGB';E={[math]::Round($_.Size / 1GB, 2)}}, @{N='FreeGB';E={[math]::Round($_.FreeSpace / 1GB, 2)}}, @{N='FreePercent';E={ if ($_.Size) { [math]::Round(($_.FreeSpace / $_.Size) * 100, 1) } }} | Format-Table -AutoSize } Write-Section $writer 'PHYSICAL DISKS' { Get-CimInstance Win32_DiskDrive | Select-Object Model, InterfaceType, MediaType, @{N='SizeGB';E={[math]::Round($_.Size / 1GB, 2)}}, FirmwareRevision, SerialNumber, Status | Format-Table -AutoSize } Write-Section $writer 'STORAGE HEALTH / RELIABILITY' { if (Get-Command Get-PhysicalDisk -ErrorAction SilentlyContinue) { Get-PhysicalDisk | Select-Object FriendlyName, MediaType, HealthStatus, OperationalStatus, @{N='SizeGB';E={[math]::Round($_.Size / 1GB, 2)}} | Format-Table -AutoSize Get-PhysicalDisk | ForEach-Object { "" "Disk: $($_.FriendlyName)" try { $_ | Get-StorageReliabilityCounter -ErrorAction Stop | Select-Object Temperature, Wear, ReadErrorsTotal, WriteErrorsTotal, PowerOnHours | Format-List } catch { 'Storage reliability counters unavailable.' } } } else { 'Get-PhysicalDisk is unavailable on this system.' } } Write-Section $writer 'INSTALLED PROGRAMS' { $paths = @( 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*', 'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*', 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' ) Get-ItemProperty $paths -ErrorAction SilentlyContinue | Where-Object { $_.DisplayName } | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate, InstallLocation | Sort-Object DisplayName -Unique | Format-Table -AutoSize } Write-Section $writer 'MICROSOFT STORE / APPX PACKAGES' { if (Get-Command Get-AppxPackage -ErrorAction SilentlyContinue) { Get-AppxPackage | Select-Object Name, Version, Publisher, Architecture | Sort-Object Name | Format-Table -AutoSize } } Write-Section $writer 'STARTUP PROGRAMS' { Get-CimInstance Win32_StartupCommand | Select-Object Name, Command, Location, User | Sort-Object Name | Format-Table -Wrap -AutoSize } Write-Section $writer 'STARTUP REGISTRY LOCATIONS' { $startupKeys = @( 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Run', 'HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce', 'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Run', 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Run', 'HKCU:\Software\Microsoft\Windows\CurrentVersion\RunOnce' ) foreach ($key in $startupKeys) { "" "[$key]" if (Test-Path $key) { $item = Get-ItemProperty $key $item.PSObject.Properties | Where-Object {$_.Name -notlike 'PS*'} | Select-Object Name, Value | Format-Table -Wrap -AutoSize } else { '(not present)' } } } Write-Section $writer 'STARTUP FOLDERS' { $folders = @( "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup", "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Startup" ) foreach ($folder in $folders) { "" "Folder: $folder" if (Test-Path $folder) { Get-ChildItem $folder -Force | Select-Object Name, FullName, LastWriteTime | Format-Table -AutoSize } else { '(not present)' } } } Write-Section $writer 'AUTOMATIC SERVICES' { Get-CimInstance Win32_Service | Where-Object {$_.StartMode -eq 'Auto'} | Select-Object Name, DisplayName, State, StartMode, StartName | Sort-Object State, DisplayName | Format-Table -AutoSize } Write-Section $writer 'AUTOMATIC SERVICES NOT RUNNING' { Get-CimInstance Win32_Service | Where-Object {$_.StartMode -eq 'Auto' -and $_.State -ne 'Running'} | Select-Object Name, DisplayName, State, StartMode | Format-Table -AutoSize } Write-Section $writer 'DEVICES WITH PROBLEMS' { if (Get-Command Get-PnpDevice -ErrorAction SilentlyContinue) { Get-PnpDevice -PresentOnly -ErrorAction SilentlyContinue | Where-Object {$_.Status -ne 'OK'} | Select-Object Status, Class, FriendlyName, InstanceId | Format-Table -Wrap -AutoSize } else { Get-CimInstance Win32_PnPEntity | Where-Object {$_.ConfigManagerErrorCode -ne 0} | Select-Object Name, PNPClass, ConfigManagerErrorCode, DeviceID | Format-Table -Wrap -AutoSize } } Write-Section $writer 'SIGNED DRIVERS' { Get-CimInstance Win32_PnPSignedDriver | Where-Object {$_.DeviceName} | Select-Object DeviceName, Manufacturer, DriverVersion, DriverDate | Sort-Object DeviceName | Format-Table -AutoSize } Write-Section $writer 'WINDOWS UPDATES / HOTFIXES' { Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object HotFixID, Description, InstalledBy, InstalledOn | Format-Table -AutoSize } Write-Section $writer 'WINDOWS DEFENDER STATUS' { if (Get-Command Get-MpComputerStatus -ErrorAction SilentlyContinue) { Get-MpComputerStatus | Select-Object AntivirusEnabled, AntispywareEnabled, RealTimeProtectionEnabled, BehaviorMonitorEnabled, IoavProtectionEnabled, NISEnabled, AntivirusSignatureLastUpdated, AntispywareSignatureLastUpdated, QuickScanAge, FullScanAge | Format-List } else { 'Microsoft Defender cmdlets unavailable.' } } Write-Section $writer 'FIREWALL PROFILES' { if (Get-Command Get-NetFirewallProfile -ErrorAction SilentlyContinue) { Get-NetFirewallProfile | Select-Object Name, Enabled, DefaultInboundAction, DefaultOutboundAction | Format-Table -AutoSize } } Write-Section $writer 'NETWORK ADAPTERS' { if (Get-Command Get-NetAdapter -ErrorAction SilentlyContinue) { Get-NetAdapter | Select-Object Name, InterfaceDescription, Status, LinkSpeed, MacAddress | Format-Table -AutoSize } } Write-Section $writer 'IP CONFIGURATION' { ipconfig /all } Write-Section $writer 'DNS SERVERS' { if (Get-Command Get-DnsClientServerAddress -ErrorAction SilentlyContinue) { Get-DnsClientServerAddress | Where-Object {$_.ServerAddresses.Count -gt 0} | Select-Object InterfaceAlias, AddressFamily, @{N='Servers';E={$_.ServerAddresses -join ', '}} | Format-Table -AutoSize } } Write-Section $writer 'ACTIVE TCP LISTENERS' { if (Get-Command Get-NetTCPConnection -ErrorAction SilentlyContinue) { Get-NetTCPConnection -State Listen -ErrorAction SilentlyContinue | Select-Object LocalAddress, LocalPort, OwningProcess | Sort-Object LocalPort | Format-Table -AutoSize } else { netstat -ano } } Write-Section $writer 'POWER PLAN' { powercfg /getactivescheme } Write-Section $writer 'BATTERY' { Get-CimInstance Win32_Battery -ErrorAction SilentlyContinue | Select-Object Name, Status, EstimatedChargeRemaining, EstimatedRunTime, BatteryStatus | Format-List } Write-Section $writer 'NON-MICROSOFT SCHEDULED TASKS' { if (Get-Command Get-ScheduledTask -ErrorAction SilentlyContinue) { Get-ScheduledTask -ErrorAction SilentlyContinue | Where-Object {$_.TaskPath -notlike '\Microsoft\*'} | Select-Object TaskName, TaskPath, State | Sort-Object TaskPath, TaskName | Format-Table -AutoSize } } Write-Section $writer 'TOP PROCESSES BY MEMORY' { Get-Process | Sort-Object WorkingSet64 -Descending | Select-Object -First 30 ProcessName, Id, @{N='MemoryMB';E={[math]::Round($_.WorkingSet64 / 1MB, 1)}}, CPU | Format-Table -AutoSize } Write-Section $writer "RECENT SYSTEM ERRORS - LAST $EventLogDays DAYS" { $start = (Get-Date).AddDays(-$EventLogDays) Get-WinEvent -FilterHashtable @{ LogName = 'System' Level = 2 StartTime = $start } -ErrorAction SilentlyContinue | Select-Object -First $MaxEventErrors TimeCreated, Id, ProviderName, Message | Format-List } Write-Section $writer "RECENT APPLICATION ERRORS - LAST $EventLogDays DAYS" { $start = (Get-Date).AddDays(-$EventLogDays) Get-WinEvent -FilterHashtable @{ LogName = 'Application' Level = 2 StartTime = $start } -ErrorAction SilentlyContinue | Select-Object -First $MaxEventErrors TimeCreated, Id, ProviderName, Message | Format-List } Write-Section $writer 'WINDOWS COMPONENT STORE STATUS' { DISM.exe /Online /Cleanup-Image /CheckHealth } Write-Section $writer 'SYSTEM FILE CHECK - VERIFY ONLY' { sfc.exe /verifyonly } Write-Section $writer 'IMPORTANT DIRECTORIES' { [PSCustomObject]@{ WindowsDirectory = $env:WINDIR SystemDrive = $env:SystemDrive ProgramFiles = $env:ProgramFiles ProgramFilesX86 = ${env:ProgramFiles(x86)} ProgramData = $env:ProgramData UserProfile = $env:USERPROFILE Temp = $env:TEMP } | Format-List } } finally { $writer.Dispose() } Write-Host Write-Host 'Report completed.' Write-Host "Saved to: $reportPath"