File tree Expand file tree Collapse file tree 2 files changed +48
-4
lines changed
reference/docs-conceptual/PSScriptAnalyzer/Rules Expand file tree Collapse file tree 2 files changed +48
-4
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
description : Use BOM encoding for non-ASCII files
3
- ms.date : 06/28/2023
3
+ ms.date : 01/07/2025
4
4
ms.topic : reference
5
5
title : UseBOMForUnicodeEncodedFile
6
6
---
@@ -13,6 +13,30 @@ title: UseBOMForUnicodeEncodedFile
13
13
For a file encoded with a format other than ASCII, ensure Byte Order Mark (BOM) is present to ensure
14
14
that any application consuming this file can interpret it correctly.
15
15
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
+
16
19
## How
17
20
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 )
Original file line number Diff line number Diff line change 1
1
---
2
2
description : Use UTF8 Encoding For Help File
3
- ms.date : 06/28/2023
3
+ ms.date : 01/07/2025
4
4
ms.topic : reference
5
5
title : UseUTF8EncodingForHelpFile
6
6
---
@@ -10,4 +10,24 @@ title: UseUTF8EncodingForHelpFile
10
10
11
11
## Description
12
12
13
- Check if help file uses UTF-8 encoding.
13
+ Check that an ` about_ ` help file uses UTF-8 encoding. The filename must start with ` about_ ` and end
14
+ with ` .help.txt ` . The rule uses the ** CurrentEncoding** property of the ** StreamReader** class to
15
+ determine the encoding of the file.
16
+
17
+ ## How
18
+
19
+ For PowerShell commands that write to files, ensure that you set the encoding parameter to ` utf8 ` ,
20
+ ` utf8BOM ` , or ` utf8NoBOM ` .
21
+
22
+ When you create a help file using a text editor, ensure that the editor is configured to save the
23
+ file in a UTF8 format. Consult the documentation for your text editor for instructions on how to
24
+ save files with a specific encoding.
25
+
26
+ ## Further reading
27
+
28
+ For more information, see the following articles:
29
+
30
+ - [ System.IO.StreamReader] ( xref:System.IO.StreamReader.CurrentEncoding%2A )
31
+ - [ about_Character_Encoding] ( /powershell/module/microsoft.powershell.core/about/about_character_encoding )
32
+ - [ Set-Content] ( xref:Microsoft.PowerShell.Management.Set-Content )
33
+ - [ Understanding file encoding in VS Code and PowerShell] ( /powershell/scripting/dev-cross-plat/vscode/understanding-file-encoding )
You can’t perform that action at this time.
0 commit comments