Skip to content

Commit 007cde0

Browse files
committed
Fix UTF8 with BOM encoding on PowerShell 6+
1 parent 0c483c7 commit 007cde0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/PSAppDeployToolkit.Tools/Public/Convert-ADTDeployment.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ function Convert-ADTDeployment
132132
$customRulePath = [System.IO.Path]::Combine($MyInvocation.MyCommand.Module.ModuleBase, 'PSScriptAnalyzer\Measure-ADTCompatibility.psm1')
133133

134134
$spBinder = [System.Management.Automation.Language.StaticParameterBinder]
135+
136+
$encoding = if ($PSVersionTable.PSVersion.Major -ge 6) { 'UTF8BOM' } else { 'UTF8' }
135137
}
136138

137139
process
@@ -282,7 +284,7 @@ function Convert-ADTDeployment
282284
#Fix to convert MARK labels to match v4 format
283285
$newScriptContent = $newScriptContent.Replace('##* MARK: PRE-INSTALLATION', '## MARK: Pre-Install').Replace('##* MARK: INSTALLATION', '## MARK: Install').Replace('##* MARK: POST-INSTALLATION', '## MARK: Post-Install').Replace('##* MARK: PRE-UNINSTALLATION', '## MARK: Pre-Uninstall').Replace('##* MARK: UNINSTALLATION', '## MARK: Uninstall').Replace('##* MARK: POST-UNINSTALLATION', '## MARK: Post-Uninstall').Replace('##* MARK: PRE-REPAIR', '## MARK: Pre-Repair').Replace('##* MARK: REPAIR', '## MARK: Repair').Replace('##* MARK: POST-REPAIR', '## MARK: Post-Repair')
284286

285-
Set-Content -Path $outputScriptPath -Value $newScriptContent -Encoding UTF8
287+
Set-Content -Path $outputScriptPath -Value $newScriptContent -Encoding $encoding
286288
}
287289
}
288290
else
@@ -358,7 +360,7 @@ function Convert-ADTDeployment
358360
$end = $hashtableAst.Right.Extent.EndOffset
359361
$scriptContent = $tempScriptAst.Extent.Text
360362
$newScriptContent = ($scriptContent.Substring(0, $start) + $hashtableContent + $scriptContent.Substring($end)).Trim()
361-
Set-Content -Path $outputScriptPath -Value $newScriptContent -Encoding UTF8
363+
Set-Content -Path $outputScriptPath -Value $newScriptContent -Encoding $encoding
362364
}
363365
else
364366
{

0 commit comments

Comments
 (0)