# Function reference

This page lists helper functions used by Win-Storage-Remediate.ps1 with a short description. Use these helpers when writing tests or adapting the script.

Function Purpose
Clear-BrowserCache Per-user browser cache cleanup for common browsers (Chrome, Edge, Firefox) using pruned enumeration and protected-path guards.
Clear-BrowserCacheAllUsers High-level routine to clear browser caches across user profiles (safe, pruned, and DryRun-aware).
Clear-DeliveryOptimizationAdvanced Advanced Delivery Optimization content cleanup for ProgramData locations (safe, non-service-disrupting removals).
Clear-DeliveryOptimizationCache Enumerates Delivery Optimization cache locations and removes safe content (pruned enumerator and protected-path checks apply).
Clear-OneDriveUserCache Per-user OneDrive cache cleaner. Avoids user documents and config files; walks directories using a stack-based enumerator to avoid reparse point traversal.
Clear-SoftwareDistributionDownload Cleans Windows Update download cache (SoftwareDistribution\\Download) using pruned enumeration.
Clear-WindowsUpdateDownloadCache Cautious Windows Update download folder cleaner (non-rebooting).
Export-EventLog Wrapper around wevtutil epl to export event logs with fallbacks for problematic channel names and quoted argument invocation.
Format-Size Small helper to convert bytes to human-friendly MB/GB strings for output.
Get-BrowserCachePathsForUser Helper that returns common browser cache paths for a given user profile (used by Clear-BrowserCacheAllUsers).
Get-ProbeSnapshot Read-only size probe: computes sizes for provided paths (used by -Estimate and diagnostic probes).
Get-RecycleBinSize Attempts to estimate Recycle Bin size via Shell.Application COM interface (best-effort; may return 0 if unavailable).
Get-SafeChildItems Safe directory enumerator that uses an explicit stack to walk folders and prunes branches that match skip/protected patterns. Use this instead of Get-ChildItem -Recurse for deletion passes.
Invoke-DISM-Safe DISM invocation wrapper that honours pending-reboot detection and the -ForceDISMWhenPending flag; logs exit codes and supports a WhatIf/DryRun fast path.
Invoke-GlobalTempCleanup Exposed cleanup pass for the machine/global TEMP folder (%TEMP).
Invoke-RemoveWithRetry Remove-Item wrapper with path canonicalisation, skip/protection checks, retry/backoff and timing/diagnostic messages.
Invoke-UserTempCleanup Exposed cleanup pass that removes per-user temp files under %USERPROFILE%\\AppData\\Local\\Temp using the safe enumerator and time budgets.
Invoke-WithRetry Generic retry wrapper that executes a provided scriptblock with configurable retries and backoff.
Merge-Log Safely consolidates the temporary runtime log into the main log. Uses file-stream copy with backoff and falls back to timestamped archive files or diagnostics if merging fails.
Resolve-FileLock Walks a directory tree (pruned) and reports on locked files; used to diagnose and optionally handle locked log files.
Save-MainLogArchive Creates per-run archives of the main log, preferring atomic Move-Item and falling back to append+truncate or diagnostic files.
Test-FileLock Lightweight check to determine whether a file is locked by attempting to open it exclusively.
Test-IsProtectedPath Canonical protection check used throughout the script; prevents touching the script's own logs/archives, reparse points, and other system-critical locations.
Test-IsSkipPath Matches a path against $skipPathPatterns (regex-first, with safe fallbacks). Returns true for paths that must not be removed or traversed.
Test-PendingReboot Detects common pending-reboot markers (Windows Update, CBS/Component-Based Servicing, PendingFileRenameOperations).
Wait-ForDISM Waits for any concurrent dism.exe processes to finish with a timeout.
Write-CustomMessage Centralised logging helper. Writes timestamped entries to the temporary log and respects the -Verbosity parameter (controls Write-Verbose/Write-Information behaviour).