Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Severity Level: Warning
Description
This rule detects files that are encoded with Unicode or other non-ASCII formats but don't include a Byte Order Mark (BOM).
When you save files with Unicode encoding, it's important to include a BOM so that applications can properly interpret the file's encoding. This rule helps ensure that your PowerShell scripts and other text files are saved with the appropriate BOM when using Unicode or similar non-ASCII encodings.
Using the Encoding parameter
When you use PowerShell commands that write to files, set the Encoding parameter to a value that produces a BOM. In PowerShell 7 and later, these encoding values produce a BOM:
bigendianunicodebigendianutf32oemunicodeutf32utf8BOM
When you create a script file using a text editor, configure the editor to save the file with a BOM. Consult your editor's documentation for instructions on how to save files with a BOM.
Example
Noncompliant
# Writes non-ASCII text without a BOM.
Set-Content -Path .\script.ps1 -Value "Write-Output 'café'" -Encoding utf8NoBOM
Compliant
# Writes non-ASCII text with a BOM.
Set-Content -Path .\script.ps1 -Value "Write-Output 'café'" -Encoding utf8BOM