Skip to content

Commit 3f528c3

Browse files
authored
Fix network error codes and improve logging
1 parent 67c2d4c commit 3f528c3

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

DeployWorkstation.ps1

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -846,10 +846,10 @@ function Install-StandardApps {
846846

847847
# Winget exit codes that indicate a transient network problem — worth retrying
848848
$networkErrorCodes = @(
849-
-1978335479, # 0x8A150109 winget download failed
850-
-1978335478, # 0x8A15010A winget network timeout
851-
-2147954407, # 0x80072EE9 connection reset by peer
852-
-2147954393, # 0x80072EF7 DNS name not resolved
849+
-1978334967, # 0x8A150109 winget download failed
850+
-1978334966, # 0x8A15010A winget network timeout
851+
-2147012887, # 0x80072EE9 connection reset by peer
852+
-2147012873, # 0x80072EF7 DNS name not resolved
853853
-2147012867 # 0x80072EFD connection refused
854854
)
855855
$maxRetries = 2
@@ -920,8 +920,9 @@ function Install-StandardApps {
920920
$script:Summary.AppsInstalled++
921921
} else {
922922
Write-Log "$(T 'InstallFail'): $($app.Name) - exit code $exitCode" -Level 'WARN'
923-
# Log last few lines of winget output to aid diagnosis
924-
$diagLines = ($wingetOut | Where-Object { $_ -and $_.Trim() }) | Select-Object -Last 5
923+
# Log last few lines of winget output to aid diagnosis.
924+
# 2>&1 can produce ErrorRecord objects alongside strings — coerce to string first.
925+
$diagLines = ($wingetOut | Where-Object { "$_".Trim() }) | Select-Object -Last 5
925926
foreach ($line in $diagLines) { Write-Log " $line" -Level 'WARN' }
926927
Add-Result -Section (T 'PhaseApps') -Item $app.Name -Status 'WARN' -Detail "Exit code $exitCode"
927928
$script:Summary.AppsFailed++
@@ -976,9 +977,11 @@ function Remove-OneDriveOem {
976977
Write-Log "--- $(T 'OneDriveOem') ---" -Level 'SECTION'
977978

978979
$setupPaths = @(
980+
# OEM-embedded binaries — these are system-wide and reliable under admin elevation.
981+
# Per-user OneDrive installs ($env:LOCALAPPDATA) are excluded: under RunAs, LOCALAPPDATA
982+
# resolves to the admin profile, not the interactive user, making the path unreliable.
979983
"$env:SystemRoot\SysWOW64\OneDriveSetup.exe",
980-
"$env:SystemRoot\System32\OneDriveSetup.exe",
981-
"$env:LOCALAPPDATA\Microsoft\OneDrive\OneDriveSetup.exe"
984+
"$env:SystemRoot\System32\OneDriveSetup.exe"
982985
)
983986

984987
foreach ($path in $setupPaths) {

0 commit comments

Comments
 (0)