mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2026-10-09 13:11:19 +11:00
feat: add automated environment report export (#5025)
* feat: add automated environment report export * refactor: address code review comments * fix: refresh toggle state in environment report * fix: surface environment report read failures * test: make registry failure explicit --------- Co-authored-by: Chris Titus <contact@christitus.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
function Get-WinUtilRecentLogs {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Concatenates WinUtil session logs from the last N days into a single text blob.
|
||||
|
||||
.PARAMETER Days
|
||||
How many days back to include. Defaults to 7, matching what the support forum/server
|
||||
typically asks users for.
|
||||
|
||||
.PARAMETER LogDirectory
|
||||
Overrides the log directory (normally $sync.winutildir\logs). Mainly for testing.
|
||||
#>
|
||||
param(
|
||||
[int]$Days = 7,
|
||||
[string]$LogDirectory
|
||||
)
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($LogDirectory)) {
|
||||
if ($null -eq $sync -or -not $sync.ContainsKey("winutildir") -or [string]::IsNullOrWhiteSpace($sync.winutildir)) {
|
||||
return ""
|
||||
}
|
||||
$LogDirectory = Join-Path $sync.winutildir "logs"
|
||||
}
|
||||
|
||||
if (-not (Test-Path $LogDirectory)) {
|
||||
return ""
|
||||
}
|
||||
|
||||
$cutoff = (Get-Date).AddDays(-$Days)
|
||||
$logFiles = Get-ChildItem -Path $LogDirectory -Filter "winutil_*.log" -File -ErrorAction SilentlyContinue |
|
||||
Where-Object { $_.LastWriteTime -ge $cutoff } |
|
||||
Sort-Object LastWriteTime
|
||||
|
||||
$sections = foreach ($logFile in $logFiles) {
|
||||
"=== $($logFile.Name) ===`n$(Get-Content -Path $logFile.FullName -Raw)"
|
||||
}
|
||||
|
||||
return ($sections -join "`n`n")
|
||||
}
|
||||
Reference in New Issue
Block a user