improve summary display
This commit is contained in:
+31
-16
@@ -7,7 +7,7 @@ Reads Cleanup* variables from the calling scope (including the RMM Run-Script
|
||||
dot-source scope). Missing variables use Get-SystemCleanupDefaults. No param()
|
||||
block deliberately: RMM variables must not be overwritten by parameter defaults.
|
||||
ReportOnly defaults to true and assesses enabled and disabled categories separately.
|
||||
It also reports hibernation/VSS usage and notes potential component-store savings without running DISM analysis.
|
||||
Category rows include hibernation/VSS usage. Component-store savings are noted without running DISM analysis.
|
||||
Server exclusions still apply. See rmm/Start-SystemCleanup.ps1 and
|
||||
docs/SystemCleanup.md for options, server exclusions, and legacy operation mapping.
|
||||
The core is self-contained; loading Tools.ps1 is the RMM shim's responsibility.
|
||||
@@ -257,6 +257,7 @@ function Invoke-SystemCleanupCategory {
|
||||
Category = $Name; Enabled = $enabled
|
||||
CandidateFiles = $(if ($native -or $blocked) { $null } else { 0 })
|
||||
CandidateBytes = $(if ($native -or $blocked) { $null } else { [long]0 })
|
||||
UsageBytes = $null; UsageNote = ''
|
||||
RemovedFiles = 0; RemovedBytes = [long]0; FailedFiles = 0
|
||||
Status = $(if ($Context.Options.ReportOnly) { 'Preview' } else { 'Completed' })
|
||||
EstimateStatus = $(if ($native) { 'Not estimated' } else { 'Estimated' })
|
||||
@@ -333,7 +334,7 @@ function Get-SystemCleanupShadowStorageDiagnostic {
|
||||
$storage = @(Get-CimInstance -ClassName Win32_ShadowStorage -ErrorAction Stop | Where-Object {
|
||||
(Get-SystemCleanupVolumeId $_.Volume) -eq $systemId
|
||||
})
|
||||
if (-not $storage.Count) { return "for $env:SystemDrive - no shadow-storage association" }
|
||||
if (-not $storage.Count) { return [pscustomobject]@{UsedBytes=[decimal]0; AllocatedBytes=[decimal]0; StoredOn=''} }
|
||||
$used = [decimal]0; $allocated = [decimal]0; $locations = @()
|
||||
foreach ($item in $storage) {
|
||||
# A missing measurement must not be converted to zero.
|
||||
@@ -346,31 +347,41 @@ function Get-SystemCleanupShadowStorageDiagnostic {
|
||||
$target = @($volumes | Where-Object { (Get-SystemCleanupVolumeId $_) -eq $targetId })
|
||||
$locations += if ($target.Count -eq 1 -and $target[0].DriveLetter) { $target[0].DriveLetter } else { 'unmounted/unknown volume' }
|
||||
}
|
||||
return ('for {0} - {1:N2} GiB used / {2:N2} GiB allocated; stored on {3}' -f $env:SystemDrive, ($used / 1GB), ($allocated / 1GB), (($locations | Select-Object -Unique) -join ', '))
|
||||
return [pscustomobject]@{UsedBytes=$used; AllocatedBytes=$allocated; StoredOn=(($locations | Select-Object -Unique) -join ', ')}
|
||||
}
|
||||
|
||||
function Get-SystemCleanupDiagnostics {
|
||||
param($Context)
|
||||
$diagnostics = [ordered]@{}
|
||||
if (-not $Context.Options.ReportOnly) { return $diagnostics }
|
||||
if ($Context.OS.IsServer) {
|
||||
$diagnostics.Hibernation = 'not assessed (server policy)'
|
||||
$diagnostics.ShadowStorage = 'not assessed (server policy)'
|
||||
} else {
|
||||
if (-not $Context.OS.IsServer) {
|
||||
# Store usage separately from candidate savings so totals do not overpromise.
|
||||
$hibernation = $Context.Stats['DisableHibernation']
|
||||
$hibernation.UsageBytes = $null
|
||||
$hibernation.UsageNote = 'file size; excluded from totals'
|
||||
try {
|
||||
$path = Join-Path $env:SystemDrive 'hiberfil.sys'
|
||||
$file = Get-Item -LiteralPath $path -Force -ErrorAction Stop
|
||||
if ($file.PSIsContainer -or ($file.Attributes -band [IO.FileAttributes]::ReparsePoint)) { throw 'Unexpected hibernation file type.' }
|
||||
$diagnostics.Hibernation = '{0}: {1:N2} GiB file size' -f $path, ($file.Length / 1GB)
|
||||
$hibernation.UsageBytes = [long]$file.Length
|
||||
} catch [System.Management.Automation.ItemNotFoundException] {
|
||||
$diagnostics.Hibernation = 'hiberfil.sys not present'
|
||||
$hibernation.UsageBytes = [long]0
|
||||
} catch {
|
||||
Write-SystemCleanupMessage "Hibernation diagnostic: $($_.Exception.Message)" -Detail
|
||||
$diagnostics.Hibernation = 'unavailable (file inspection failed; see verbose)'
|
||||
$hibernation.UsageNote = 'unavailable (file inspection failed; see verbose)'
|
||||
}
|
||||
try { $diagnostics.ShadowStorage = Get-SystemCleanupShadowStorageDiagnostic } catch {
|
||||
$shadows = $Context.Stats['ShadowCopies']
|
||||
$shadows.UsageBytes = $null
|
||||
$shadows.UsageNote = 'VSS used; excluded from totals'
|
||||
try {
|
||||
$storage = Get-SystemCleanupShadowStorageDiagnostic
|
||||
$shadows.UsageBytes = $storage.UsedBytes
|
||||
if ($storage.UsedBytes -gt 0) { $shadows.UsageNote += '; newest retained' }
|
||||
if ($storage.StoredOn) { $shadows.UsageNote += '; stored on ' + $storage.StoredOn }
|
||||
Write-SystemCleanupMessage ('Shadow storage for {0}: {1:N2} MiB used / {2:N2} MiB allocated; stored on {3}' -f $env:SystemDrive, ($storage.UsedBytes / 1MB), ($storage.AllocatedBytes / 1MB), $storage.StoredOn) -Detail
|
||||
} catch {
|
||||
Write-SystemCleanupMessage "Shadow-storage diagnostic: $($_.Exception.Message)" -Detail
|
||||
$diagnostics.ShadowStorage = 'unavailable (storage inspection failed; see verbose)'
|
||||
$shadows.UsageNote = 'unavailable (storage inspection failed; see verbose)'
|
||||
}
|
||||
}
|
||||
# Avoid slow DISM analysis during previews; potential savings are not measured.
|
||||
@@ -384,7 +395,7 @@ function Write-SystemCleanupReport {
|
||||
$totals = Get-SystemCleanupReportTotals $Context
|
||||
Write-SystemCleanupMessage ('Known savings: ENABLED {0:N2} MiB ({1:N0} files); additional DISABLED {2:N2} MiB ({3:N0} files).' -f ($totals.EnabledBytes / 1MB), $totals.EnabledFiles, ($totals.AdditionalDisabledBytes / 1MB), $totals.AdditionalDisabledFiles)
|
||||
if ($Context.ContainsKey('Diagnostics') -and $Context.Diagnostics.Count) {
|
||||
Write-SystemCleanupMessage 'DIAGNOSTICS - current usage/potential, excluded from savings totals'
|
||||
Write-SystemCleanupMessage 'DIAGNOSTICS - potential, excluded from savings totals'
|
||||
foreach ($entry in $Context.Diagnostics.GetEnumerator()) {
|
||||
Write-SystemCleanupMessage (" {0}: {1}" -f $entry.Key, $entry.Value)
|
||||
}
|
||||
@@ -404,13 +415,17 @@ function Write-SystemCleanupReport {
|
||||
Write-SystemCleanupMessage $heading
|
||||
if (-not $rows.Count) { Write-SystemCleanupMessage ' None.' }
|
||||
foreach ($row in $rows) {
|
||||
$files = '-'; $size = '-'; $notes = @()
|
||||
if ($row.EstimateStatus -eq 'Not estimated') { $notes += 'not estimated' }
|
||||
$files = '-'; $size = '-'; $notes = @(); $bytes = $null
|
||||
if ($row.UsageNote) {
|
||||
$bytes = $row.UsageBytes
|
||||
$notes += $row.UsageNote
|
||||
} elseif ($row.EstimateStatus -eq 'Not estimated') { $notes += 'not estimated' }
|
||||
elseif ($row.EstimateStatus -eq 'Not assessed') { $notes += 'not assessed' }
|
||||
elseif ($null -ne $row.CandidateBytes) {
|
||||
$files = '{0:N0}' -f $row.CandidateFiles
|
||||
$size = if ($row.CandidateBytes -gt 0 -and $row.CandidateBytes -lt (0.01 * 1MB)) { '<0.01' } else { '{0:N2}' -f ($row.CandidateBytes / 1MB) }
|
||||
$bytes = $row.CandidateBytes
|
||||
} else { $notes += 'unavailable' }
|
||||
if ($null -ne $bytes) { $size = if ($bytes -gt 0 -and $bytes -lt (0.01 * 1MB)) { '<0.01' } else { '{0:N2}' -f ($bytes / 1MB) } }
|
||||
if ($row.Status -notin @('Preview', 'Blocked on server')) { $notes += $row.Status }
|
||||
if ($row.EstimateStatus -eq 'Incomplete') { $notes += 'incomplete' }
|
||||
if ($row.FailedFiles) { $notes += "$($row.FailedFiles) files skipped" }
|
||||
|
||||
Reference in New Issue
Block a user