From be4396ce83e4352a0c58b81c9e447544ec674628 Mon Sep 17 00:00:00 2001 From: Simone Date: Sun, 17 May 2026 22:31:34 +0200 Subject: [PATCH] fix(scripts): satisfy PSScriptAnalyzer (lint gate) - Remove-Securely: suppress PSUseShouldProcessForStateChangingFunctions (internal best-effort shred; ShouldProcess prompts are undesirable) + add [CmdletBinding()]. - Replace the two empty catch blocks (Set-CIGuestCredential.ps1, Test-CIGuestWinRM.ps1) with Write-Verbose so PSAvoidUsingEmptyCatchBlock is satisfied while keeping best-effort behavior. Co-Authored-By: Claude Opus 4.7 --- scripts/Set-CIGuestCredential.ps1 | 9 ++++++++- scripts/Test-CIGuestWinRM.ps1 | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/Set-CIGuestCredential.ps1 b/scripts/Set-CIGuestCredential.ps1 index e999be9..abf562c 100644 --- a/scripts/Set-CIGuestCredential.ps1 +++ b/scripts/Set-CIGuestCredential.ps1 @@ -115,6 +115,11 @@ function Invoke-AsSystem { # --- Harden + shred helper for the transient secret file ------------------ function Remove-Securely { + # Best-effort cleanup helper; ShouldProcess prompting is undesirable + # for an internal shred-and-delete of our own temp file. + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseShouldProcessForStateChangingFunctions', '')] + [CmdletBinding()] param([Parameter(Mandatory)] [string] $Path) if (-not (Test-Path -LiteralPath $Path)) { return } try { @@ -124,7 +129,9 @@ function Remove-Securely { [Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($rnd) [IO.File]::WriteAllBytes($Path, $rnd) } - } catch { } + } catch { + Write-Verbose "secure overwrite failed (continuing to delete): $_" + } Remove-Item -LiteralPath $Path -Force -ErrorAction SilentlyContinue } diff --git a/scripts/Test-CIGuestWinRM.ps1 b/scripts/Test-CIGuestWinRM.ps1 index 00e6823..677e888 100644 --- a/scripts/Test-CIGuestWinRM.ps1 +++ b/scripts/Test-CIGuestWinRM.ps1 @@ -116,7 +116,9 @@ try { $cn = $ssl.RemoteCertificate.Subject # e.g. "CN=WINBUILD" if ($cn -match 'CN=([^,]+)') { $guestCn = $Matches[1].Trim() } $ssl.Dispose(); $tcpc.Close() -} catch { } +} catch { + Write-Verbose "cert CN probe failed (hostname auto-detect skipped): $_" +} if ($guestCn) { Write-Host " guest cert CN (hostname): $guestCn" -ForegroundColor Cyan }