diff --git a/README.md b/README.md index bdcc91e..99c0fdc 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,15 @@ A dependency-free, non-GUI Windows diagnostics and maintenance-information colle `WindowsMaintenanceReport.ps1` provides three levels of reporting: -* **Compact** — quick maintenance snapshot, default +* **Compact** — quick maintenance snapshot (`-Compact`) * **Mid** — useful hardware, software, startup and driver inventory -* **Full** — comprehensive diagnostics +* **Full** — comprehensive diagnostics, default (`-Full` is optional) No Python, third-party PowerShell modules, or installation is required on the Windows machine. ## Quick Start -### Compact report +### Full report — Default Open PowerShell and run: @@ -22,18 +22,19 @@ irm 'https://proxy.dandaedre.com/gitea/Dandaedre/WinDiagnostics/raw/branch/main/ This downloads the latest version into memory and executes it without saving the script to disk. -The default report is intentionally compact and is intended to provide a quick overview in roughly 20 lines. +The default report collects Full diagnostics. Use `-Compact` for a quick snapshot or `-Mid` for an inventory. Admin-only checks are skipped when PowerShell is not elevated. For access to all available diagnostics, running PowerShell **as Administrator** is recommended. ## Report Levels -### Compact — Default +### Compact — Explicit opt-in -Run: +Retrieve the script and select `-Compact`: ```powershell -irm 'https://proxy.dandaedre.com/gitea/Dandaedre/WinDiagnostics/raw/branch/main/WindowsMaintenanceReport.ps1' | iex +$src = irm 'https://proxy.dandaedre.com/gitea/Dandaedre/WinDiagnostics/raw/branch/main/WindowsMaintenanceReport.ps1' +& ([ScriptBlock]::Create($src)) -Compact ``` The compact report provides a quick maintenance snapshot including: @@ -89,9 +90,9 @@ The Mid report includes: Logical disks, physical disks, and storage-health information are combined into a single storage section. -## Full Report +## Full Report — Default -For the complete diagnostic report: +Full runs when no mode switch is supplied. You can also request it explicitly: ```powershell $src = irm 'https://proxy.dandaedre.com/gitea/Dandaedre/WinDiagnostics/raw/branch/main/WindowsMaintenanceReport.ps1' @@ -129,12 +130,18 @@ Full mode is read-only and intended to collect evidence for troubleshooting. It ## Local Usage -If you already have the script: +If you already have the script, run Full diagnostics with: ```powershell .\WindowsMaintenanceReport.ps1 ``` +Compact report: + +```powershell +.\WindowsMaintenanceReport.ps1 -Compact +``` + Mid report: ```powershell @@ -157,6 +164,13 @@ This applies `ExecutionPolicy Bypass` only to that PowerShell process and does n ## Options +### Report Mode + +Omit the mode switch for Full diagnostics, or choose exactly one of `-Full`, +`-Mid`, or `-Compact`. Combining mode switches is an error. + +View built-in help with `Get-Help .\WindowsMaintenanceReport.ps1 -Detailed`. + ### Output Directory Reports are saved in the current user's Documents folder by default, including when Windows redirects that folder to OneDrive or a network location. @@ -276,7 +290,7 @@ sfc.exe /scannow WinDiagnostics works well with an interactive PowerShell session obtained through Windows Remote Management / WinRM. -Once connected to the Windows machine, the compact report can be executed directly: +Once connected to the Windows machine, the default Full report can be executed directly: ```powershell irm 'https://proxy.dandaedre.com/gitea/Dandaedre/WinDiagnostics/raw/branch/main/WindowsMaintenanceReport.ps1' | iex @@ -384,21 +398,27 @@ When administering Windows remotely from another machine, the Windows target mus ## Quick Reference ```powershell -# Compact +# Full (default) irm 'https://proxy.dandaedre.com/gitea/Dandaedre/WinDiagnostics/raw/branch/main/WindowsMaintenanceReport.ps1' | iex # Download into memory $src = irm 'https://proxy.dandaedre.com/gitea/Dandaedre/WinDiagnostics/raw/branch/main/WindowsMaintenanceReport.ps1' +# Compact +& ([ScriptBlock]::Create($src)) -Compact + # Mid & ([ScriptBlock]::Create($src)) -Mid # Full & ([ScriptBlock]::Create($src)) -Full -# Local +# Local Full (default) .\WindowsMaintenanceReport.ps1 +# Local Compact +.\WindowsMaintenanceReport.ps1 -Compact + # Local Mid .\WindowsMaintenanceReport.ps1 -Mid @@ -442,6 +462,7 @@ Run each command in both a normal and an elevated Windows PowerShell 5.1 session ```powershell .\WindowsMaintenanceReport.ps1 +.\WindowsMaintenanceReport.ps1 -Compact .\WindowsMaintenanceReport.ps1 -Mid .\WindowsMaintenanceReport.ps1 -Full .\WindowsMaintenanceReport.ps1 -Full -EventLogDays 30 diff --git a/WindowsMaintenanceReport.ps1 b/WindowsMaintenanceReport.ps1 index 231fdbb..b1f9d09 100644 --- a/WindowsMaintenanceReport.ps1 +++ b/WindowsMaintenanceReport.ps1 @@ -1,36 +1,63 @@ #requires -Version 5.1 <# -WindowsMaintenanceReport.ps1 +.SYNOPSIS +Collects a Windows diagnostic report as UTF-8 JSON. -Produces a structured JSON report instead of a human-formatted TXT report. - -Modes: - Default Compact maintenance snapshot - -Mid Hardware/software/startup/driver inventory - -Full Everything, including networking, event logs, processes, - driver stores, kernel/filter drivers, services, virtualization, - storage/PnP, Code Integrity, reliability and crash metadata. - Includes read-only DISM and SFC verification when elevated. +.DESCRIPTION +Full diagnostics run by default, including hardware, software, driver stores, +kernel/filter drivers, services, virtualization, storage/PnP, networking, events, +Code Integrity, reliability and crash metadata. DISM and SFC verification run +when elevated. Use -Mid for an inventory or -Compact for a quick snapshot. All modes support non-administrator sessions. Restricted or unavailable checks are recorded in the JSON and collection continues. Full mode collects evidence; it does not automatically diagnose, repair, update, disable, uninstall or replace -drivers or devices. Schema version 2 adds collection status and bounded events. +drivers or devices. PowerShell 5.1 is supported. Output uses schema version 2. -Examples: - .\WindowsMaintenanceReport.ps1 - .\WindowsMaintenanceReport.ps1 -Mid - .\WindowsMaintenanceReport.ps1 -Full - .\WindowsMaintenanceReport.ps1 -Mid -OutputDirectory C:\Temp - .\WindowsMaintenanceReport.ps1 -Full -EventLogDays 30 +.PARAMETER Compact +Collect a quick maintenance snapshot instead of the default Full report. -The report is UTF-8 JSON and is designed to be both human-readable and -machine-readable. PowerShell 5.1 is supported without extra modules. +.PARAMETER Mid +Collect hardware, software, startup and driver inventory. + +.PARAMETER Full +Explicitly select Full diagnostics, the default when no mode is specified. +Choose only one of -Compact, -Mid or -Full. + +.PARAMETER OutputDirectory +Save the report in this writable directory. Defaults to the user's Documents +folder, with the temporary directory as a fallback. + +.PARAMETER EventLogDays +Number of days of event and reliability history to collect. Defaults to 7. + +.PARAMETER MaxEventErrors +Maximum events returned per event log, including warnings. Defaults to 100. + +.PARAMETER JsonDepth +JSON serialization depth. Defaults to 12. + +.EXAMPLE +.\WindowsMaintenanceReport.ps1 +Runs Full diagnostics. + +.EXAMPLE +.\WindowsMaintenanceReport.ps1 -Compact +Collects a quick maintenance snapshot. + +.EXAMPLE +.\WindowsMaintenanceReport.ps1 -Mid -OutputDirectory C:\Temp +Collects an inventory and saves it in C:\Temp. + +.EXAMPLE +.\WindowsMaintenanceReport.ps1 -Full -EventLogDays 30 +Runs Full diagnostics with 30 days of history. #> [CmdletBinding()] param( + [switch]$Compact, [switch]$Mid, [switch]$Full, @@ -48,8 +75,8 @@ param( $ErrorActionPreference = 'Continue' -if ($Mid -and $Full) { - throw 'Choose either -Mid or -Full, not both.' +if (($Compact -and $Mid) -or ($Compact -and $Full) -or ($Mid -and $Full)) { + throw 'Choose only one of -Compact, -Mid or -Full.' } function Test-IsAdministrator { @@ -380,9 +407,9 @@ elseif (-not (Test-DirectoryWritable $OutputDirectory)) { throw "Output directory is not writable: $OutputDirectory" } -$mode = 'Compact' -if ($Mid) { $mode = 'Mid' } -if ($Full) { $mode = 'Full' } +$mode = 'Full' +if ($Compact) { $mode = 'Compact' } +if ($Mid) { $mode = 'Mid' } $startedAt = Get-Date $timestamp = $startedAt.ToString('yyyyMMdd_HHmmss') @@ -689,7 +716,7 @@ else { # ---------------------------------------------------------------------- # FULL-ONLY SECTIONS # ---------------------------------------------------------------------- - if ($Full) { + if ($mode -eq 'Full') { $report.sections.system_drivers = Invoke-ReportSection 'System drivers' { Get-CimInstance Win32_SystemDriver | Select-Object Name, DisplayName, State, StartMode, PathName, ServiceType @@ -1006,7 +1033,7 @@ else { } } -if ($Full) { +if ($mode -eq 'Full') { $report.diagnostic_collection = [ordered]@{} foreach ($key in $report.sections.Keys) { $report.diagnostic_collection[$key] = ($report.sections[$key].status -eq 'ok')