fix: Exchange monitor encoding for PS 5.1 (v1.6.3)

ASCII runtime strings in Exchange-MailSecurity and Notify-Common avoid parser errors when scripts are copied without UTF-8 BOM. Deploy copies .ps1 to ProgramData with UTF-8 BOM via Copy-ScriptFileWithUtf8Bom.
This commit is contained in:
2026-05-22 14:57:35 +10:00
parent 7c13c96622
commit 872df98a2c
5 changed files with 101 additions and 82 deletions
+20 -2
View File
@@ -1,4 +1,4 @@
<#
<#
.SYNOPSIS
Deploy domain monitor scripts (Exchange / AD) from share to ProgramData.
.PARAMETER Target
@@ -47,6 +47,20 @@ function Write-TextFileUtf8Bom {
[System.IO.File]::WriteAllText($Path, $Text, $Utf8Bom)
}
function Copy-ScriptFileWithUtf8Bom {
param(
[Parameter(Mandatory = $true)][string]$SourcePath,
[Parameter(Mandatory = $true)][string]$DestPath
)
$raw = [System.IO.File]::ReadAllBytes($SourcePath)
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
$text = $utf8NoBom.GetString($raw)
if ($text.Length -gt 0 -and [int][char]$text[0] -eq 0xFEFF) {
$text = $text.Substring(1)
}
[System.IO.File]::WriteAllText($DestPath, $text, $Utf8Bom)
}
function Resolve-SourceShareRoot {
if (-not [string]::IsNullOrWhiteSpace($SourceShareRoot)) {
return [System.IO.Path]::GetFullPath($SourceShareRoot.TrimEnd('\'))
@@ -128,7 +142,11 @@ foreach ($name in $filesToCopy) {
Write-DeployLog "WhatIf: copy $src -> $dst"
continue
}
Copy-Item -LiteralPath $src -Destination $dst -Force
if ($name -like '*.ps1') {
Copy-ScriptFileWithUtf8Bom -SourcePath $src -DestPath $dst
} else {
Copy-Item -LiteralPath $src -Destination $dst -Force
}
Write-DeployLog "Copied: $name"
}