diff --git a/src/Audit/Write-PersonaAuditRecord.ps1 b/src/Audit/Write-PersonaAuditRecord.ps1 index cf06407..5624a48 100644 --- a/src/Audit/Write-PersonaAuditRecord.ps1 +++ b/src/Audit/Write-PersonaAuditRecord.ps1 @@ -69,12 +69,20 @@ function Write-PersonaAuditRecord { $directory = Split-Path -Parent $Path if ($directory -and -not (Test-Path -LiteralPath $directory)) { - $null = New-Item -ItemType Directory -Path $directory -Force + $null = New-Item -ItemType Directory -Path $directory -Force -WhatIf:$false -Confirm:$false } # Append, one record per line. UTF-8 without BOM so the file is # machine-readable by any NDJSON consumer. - Add-Content -LiteralPath $Path -Value $line -Encoding utf8NoBOM -ErrorAction Stop + # + # -WhatIf:$false / -Confirm:$false pin this call regardless of any + # ambient $WhatIfPreference in the caller's session (e.g. left set by + # dot-sourcing an earlier -WhatIf run). Add-Content honours + # ShouldProcess, and this sink is not optional under -WhatIf - the + # audit trail is what makes preview mode auditable at all, so it must + # write unconditionally, independent of anything the caller's scope + # happens to have set. + Add-Content -LiteralPath $Path -Value $line -Encoding utf8NoBOM -ErrorAction Stop -WhatIf:$false -Confirm:$false } catch { if ($null -ne $State -and $State.FileSinkFailed) { return }