Skip to content

Commit c3d279a

Browse files
committed
Provide more guidance for file encoding
1 parent 56235ca commit c3d279a

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

reference/docs-conceptual/PSScriptAnalyzer/Rules/UseBOMForUnicodeEncodedFile.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
description: Use BOM encoding for non-ASCII files
3-
ms.date: 06/28/2023
3+
ms.date: 01/07/2025
44
ms.topic: reference
55
title: UseBOMForUnicodeEncodedFile
66
---
@@ -13,6 +13,30 @@ title: UseBOMForUnicodeEncodedFile
1313
For a file encoded with a format other than ASCII, ensure Byte Order Mark (BOM) is present to ensure
1414
that any application consuming this file can interpret it correctly.
1515

16+
You can use this rule to test any arbitrary text file, but the intent is to ensure that PowerShell
17+
scripts are saved with a BOM when using a Unicode encoding.
18+
1619
## How
1720

18-
Ensure that the file is encoded with BOM present.
21+
For PowerShell commands that write to files, ensure that you set the encoding parameter to a value
22+
that produces a BOM. In PowerShell 7 and higher, the following values of the **Encoding** parameter
23+
produce a BOM:
24+
25+
- `bigendianunicode`
26+
- `bigendianutf32`
27+
- `oem`
28+
- `unicode`
29+
- `utf32`
30+
- `utf8BOM`
31+
32+
When you create a script file using a text editor, ensure that the editor is configured to save the
33+
file with a BOM. Consult the documentation for your text editor for instructions on how to save
34+
files with a BOM.
35+
36+
## Further reading
37+
38+
For more information, see the following articles:
39+
40+
- [about_Character_Encoding](/powershell/module/microsoft.powershell.core/about/about_character_encoding)
41+
- [Set-Content](xref:Microsoft.PowerShell.Management.Set-Content)
42+
- [Understanding file encoding in VS Code and PowerShell](/powershell/scripting/dev-cross-plat/vscode/understanding-file-encoding)

0 commit comments

Comments
 (0)