Public/Export-PathReport.ps1
|
function Export-PathReport { <# .SYNOPSIS Exports a PATH analysis report to JSON. .DESCRIPTION Generates a comprehensive report of the PATH analysis and saves it to a JSON file. .PARAMETER Path Output file path. Defaults to current directory with timestamp. .EXAMPLE Export-PathReport .EXAMPLE Export-PathReport -Path "C:\Reports\path-report.json" #> [CmdletBinding()] [OutputType([PSCustomObject])] param( [string]$Path = (Join-Path (Get-Location) "path-report_$(Get-Date -Format 'yyyy-MM-dd_HH-mm-ss').json") ) $analysis = Get-PathAnalysis -Target Both $entries = Get-PathEntries -Target Both $report = @{ GeneratedAt = (Get-Date).ToString('o') GeneratedBy = 'WinPath-Clean' Version = $script:ModuleVersion Computer = $env:COMPUTERNAME User = $env:USERNAME Summary = @{ TotalEntries = $analysis.Count UserEntries = ($analysis | Where-Object { $_.Scope -eq 'User' }).Count MachineEntries = ($analysis | Where-Object { $_.Scope -eq 'Machine' }).Count ValidEntries = ($analysis | Where-Object { $_.Status -eq '✓' }).Count DuplicateEntries = ($analysis | Where-Object { $_.Issue -like '*Duplicate*' }).Count ObsoleteEntries = ($analysis | Where-Object { $_.Issue -like '*exist*' }).Count UserPathLength = ($entries.User -join ';').Length MachinePathLength = ($entries.Machine -join ';').Length } Entries = @($analysis | ForEach-Object { @{ Status = $_.Status Path = $_.Path Scope = $_.Scope Exists = $_.Exists Issue = $_.Issue ExpandedPath = $_.ExpandedPath } }) Issues = @($analysis | Where-Object { $_.Status -ne '✓' } | ForEach-Object { @{ Path = $_.Path Scope = $_.Scope Issue = $_.Issue } }) } $report | ConvertTo-Json -Depth 10 | Out-File -FilePath $Path -Encoding UTF8 Write-Host Write-Host " ✓ Report exported to: $Path" -ForegroundColor Green Write-Host return [PSCustomObject]@{ ReportFile = $Path TotalEntries = $report.Summary.TotalEntries IssuesFound = $report.Issues.Count } } |