From ee7f406f2a38afe04d6d50acda2d3156508f842b Mon Sep 17 00:00:00 2001 From: Simone Date: Sun, 10 May 2026 17:17:41 +0200 Subject: [PATCH] fix(setup): Measure-Object .Sum null-dereference under Set-StrictMode -Version Latest PS 5.1 treats GenericMeasureInfo.Sum as absent (not null) when the input pipe is empty. StrictMode throws 'property Sum cannot be found'. Replace Measure-Object with an explicit foreach loop for SoftwareDistribution size reporting. Co-Authored-By: Claude Sonnet 4.6 --- template/Setup-WinBuild2025.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/template/Setup-WinBuild2025.ps1 b/template/Setup-WinBuild2025.ps1 index 5032ac8..c1f2067 100644 --- a/template/Setup-WinBuild2025.ps1 +++ b/template/Setup-WinBuild2025.ps1 @@ -1031,7 +1031,11 @@ Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\wuauserv' ` # normal and harmless: WU is permanently disabled by Step 6b (service Disabled + GPO keys). # Report remaining size as informational only. $sdFiles = Get-ChildItem 'C:\Windows\SoftwareDistribution\Download' -Recurse -File -Force -ErrorAction SilentlyContinue -$sdMB = [math]::Round(($sdFiles | Measure-Object -Property Length -Sum).Sum / 1MB, 1) +# Avoid Measure-Object .Sum: under Set-StrictMode -Version Latest, PS 5.1 treats the +# nullable Sum property as absent when the pipe is empty, throwing "property not found". +$sdBytes = [long]0 +if ($sdFiles) { foreach ($f in $sdFiles) { $sdBytes += $f.Length } } +$sdMB = [math]::Round($sdBytes / 1MB, 1) Write-Host " SoftwareDistribution\Download: $($sdFiles.Count) file(s), ${sdMB} MB remaining (WaaSMedicSvc best-effort, WU is disabled)." Assert-Step 'Cleanup' 'wuauserv StartType Disabled after cache clear' {