From 2e51ff0ed1ca00ccfecdd88f24ac5c9f78830db8 Mon Sep 17 00:00:00 2001 From: Andreas Jordan Date: Sat, 12 Sep 2026 15:25:43 +0200 Subject: [PATCH] Get-LoginPasswordHash - Stop eating the caller loop when the hash query fails Stop-Function -Continue runs PowerShell's continue. No loop encloses this call site inside the command, so the continue unwound out of the command and consumed an iteration of whatever loop the caller runs in: a user's foreach silently skipped an element, and Pester's runner corrupted. The escape only bites the non-EnableException path; with EnableException Stop-Function throws before it gets there. Latent: the only caller, Sync-DbaLoginPassword, calls it inside its login loop, so the continue was caught there - but it bypassed the caller's null-hash handling and the return that follows the call never ran. No red-on-old test exists for a latent escape; the return after the call now runs as written. Part of #10638 (do Get-LoginPasswordHash) Co-Authored-By: Claude Fable 5.1 --- private/functions/Get-LoginPasswordHash.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/private/functions/Get-LoginPasswordHash.ps1 b/private/functions/Get-LoginPasswordHash.ps1 index 343e1f7e871..6e1518fcdba 100644 --- a/private/functions/Get-LoginPasswordHash.ps1 +++ b/private/functions/Get-LoginPasswordHash.ps1 @@ -68,7 +68,9 @@ function Get-LoginPasswordHash { $hashedPassDt = $server.ConnectionContext.ExecuteWithResults($sql) $hashedPass = $hashedPassDt.Tables[0].Rows[0].Item(0) } catch { - Stop-Function -Message "Failed to retrieve password hash for login $($Login.Name)" -ErrorRecord $_ -Target $Login -Continue + # No -Continue here: no loop encloses this catch, so the continue would escape the function + # and bypass the null-hash handling of the caller (#10638). + Stop-Function -Message "Failed to retrieve password hash for login $($Login.Name)" -ErrorRecord $_ -Target $Login return } }