From 213c400f620545c9df5857dc69571567e2922b48 Mon Sep 17 00:00:00 2001 From: Tomas Kracmar Date: Mon, 13 Oct 2025 12:48:45 +0200 Subject: [PATCH] UTF-8 default encoding --- Test-WeakADPasswords.ps1 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Test-WeakADPasswords.ps1 b/Test-WeakADPasswords.ps1 index 8dd0075..5325887 100644 --- a/Test-WeakADPasswords.ps1 +++ b/Test-WeakADPasswords.ps1 @@ -28,6 +28,15 @@ $VerbosePreference = "Continue" $scriptRoot = $PSScriptRoot +# Ensure consistent UTF-8 output for files across PS5.1/PS7 +try { + $PSDefaultParameterValues['Out-File:Encoding'] = 'utf8' + $PSDefaultParameterValues['Set-Content:Encoding'] = 'utf8' + $PSDefaultParameterValues['Add-Content:Encoding'] = 'utf8' + # Also align $OutputEncoding for external writes + $OutputEncoding = New-Object System.Text.UTF8Encoding($false) +} catch { } + function Start-TestTranscript { param([string]$BasePath) try { @@ -286,10 +295,10 @@ function Test-WeakADPasswords { $upnOnlyContent = $upnReportContent -join "`r`n" try { - $updatedReportContent | Out-File -FilePath $reportPath -ErrorAction Stop + $updatedReportContent | Out-File -FilePath $reportPath -Encoding utf8 -ErrorAction Stop Write-Host "Report saved to $reportPath" - $upnOnlyContent | Out-File -FilePath $upnOnlyReportPath -ErrorAction Stop + $upnOnlyContent | Out-File -FilePath $upnOnlyReportPath -Encoding utf8 -ErrorAction Stop Write-Host "UPN-only report saved to $upnOnlyReportPath" } catch { Write-Error ("Failed to save report: {0}" -f $_.Exception.Message)