Private/Invoke-SqlSpnNativeCall.ps1
|
# ============================================================================= # Script : Invoke-SqlSpnNativeCall.ps1 # Author : Keith Ramsey # ============================================================================= # Change Log # ----------------------------------------------------------------------------- # 2026-05-09 Keith Ramsey Phase 2 release polish - DR-202 standard header applied. # 2026-05-14 Keith Ramsey CRITICAL: pass arguments as an array, not a single # pre-joined string. `setspn.exe $string` delivers one # argv token, so setspn never parsed -Q/-S correctly: # duplicate detection and registration were both inert. # Masked because 100% of Pester tests mock this function. # Surfaced by first real-domain lab run (SQL 2025). # ============================================================================= function Invoke-SqlSpnNativeCall { <# .SYNOPSIS Thin wrapper around setspn.exe to allow Pester mocking. .DESCRIPTION Pester cannot mock external executables directly, but it can mock function calls. Centralizing every setspn.exe invocation here means tests can substitute a mock and assert on the argument string passed to the underlying tool. .PARAMETER ArgumentList The argument tokens passed to setspn.exe, one element per argv token (e.g., @('-S','MSSQLSvc/host:1433','CN=acct,OU=Service Accounts,DC=x')). Passing an array (not a pre-joined string) is required so tokens that contain spaces -- notably account DNs with OUs like 'Domain Controllers' -- survive as a single argument to setspn.exe. #> [CmdletBinding()] param([Parameter(Mandatory=$true)][string[]]$ArgumentList) setspn.exe @ArgumentList } |