#
Function reference
#
On this page
Function list Function reference (selected helpers) Write-CustomMessage Get-RecycleBinSize Invoke-DISM-Safe Invoke-RemoveWithRetry
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 list
#
Function reference (selected helpers)
#
Write-CustomMessage
- Signature:
Write-CustomMessage -Message <string> [-Level <string>] [-Verbose] - Purpose: Centralised log-first writer used throughout the remediation script.
- Parameters:
- Message: The textual message to record.
- Level: Optional severity string (for example, 'INFO', 'WARN', 'ERROR'). Defaults to 'INFO' when omitted.
- Verbose: When supplied (or when the run is started with
-Verbosity Verbose), the function emitsWrite-Verboseoutput in addition to appending to the temp log.
- Behaviour:
- Always appends a timestamped, single-line entry to the per-run temporary log file (located in
%TEMP%). - Emits host verbose output only when verbosity is enabled; this keeps Intune-captured host output compact while preserving detailed diagnostics in the temp log.
- Sanitises input to avoid logging PII in host output; full details remain in the temp log only.
- Always appends a timestamped, single-line entry to the per-run temporary log file (located in
- Return: None (writes to log and optionally to the host verbose stream).
#
Get-RecycleBinSize
- Signature:
Get-RecycleBinSize [-Path <string>] [-AsInt64] - Purpose: Best-effort estimation of Recycle Bin usage for the specified volume or the system volume.
- Parameters:
- Path: Optional path or drive spec used to scope the probe. If omitted the function probes the system (C:) bin.
- AsInt64: When present the function returns a stable
[int64]value.
- Behaviour:
- Attempts a Shell.Application COM query first (the most accurate when available).
- If COM is unavailable or fails, falls back to a conservative per-user
Recycle.Binenumeration and normalises the result to an[int64]number of bytes. - May return
0when the bin cannot be probed due to access restrictions (for example running under different accounts or as SYSTEM in some hosts).
- Return:
[int64]number of bytes (0 when unknown or inaccessible).
#
Invoke-DISM-Safe
- Signature:
Invoke-DISM-Safe [-WhatIf] [-ForceDISMWhenPending] [-TimeoutSec <int>] - Purpose: Run DISM component store cleanup while respecting pending-reboot detection and
ShouldProcesssemantics. - Parameters:
- WhatIf: Honour
ShouldProcessdry-run semantics (the function supports-WhatIf/-Confirm). - ForceDISMWhenPending: Overrides pending-reboot gating and forces DISM to run even when a reboot is pending.
- TimeoutSec: Optional timeout (seconds) for the DISM call.
- WhatIf: Honour
- Behaviour:
- Detects common pending-reboot markers and will skip DISM unless
ForceDISMWhenPendingis supplied or the file-level preference$Pref_ForceDISMWhenPendingOverrideis set. - Calls
Wait-ForDISMto ensure no concurrentdism.exeprocesses are running (with retries/backoff). - Logs exit codes, duration, and relevant diagnostics to the per-run temp log.
- Declared with
SupportsShouldProcessso callers can use-WhatIfsafely in tests.
- Detects common pending-reboot markers and will skip DISM unless
- Return:
[int]DISM exit code (0 for success). See logs for details on non-zero values.
#
Invoke-RemoveWithRetry
- Signature:
Invoke-RemoveWithRetry -Path <string> [-Retries <int>] [-BackoffMs <int>] [-DryRun] - Purpose: Safe removal helper that canonicalises paths, checks skip/protected patterns, and retries common transient failure modes.
- Parameters:
- Path: Full path to remove (file or directory). The helper performs canonicalisation and protection checks.
- Retries: Number of retry attempts (default: 3).
- BackoffMs: Milliseconds to wait between retries (default: 500).
- DryRun: When supplied, the helper logs what it would remove without performing destructive actions.
- Behaviour:
- Verifies that the target path is not a protected or skip-path using
Test-IsProtectedPath/Test-IsSkipPath. - Attempts removal with
Remove-Item -Force -Recurse(when safe) and retries on transient errors such as sharing violations. - Writes per-attempt diagnostics to the per-run temp log; only concise summaries are emitted to the host.
- Verifies that the target path is not a protected or skip-path using
- Return:
[bool]true on successful removal or whenDryRunis set; false on permanent failure (details in the per-run temp log).