> ## Documentation Index
> Fetch the complete documentation index at: https://tally.wharflab.com/llms.txt
> Use this file to discover all available pages before exploring further.

# powershell/PSUseBOMForUnicodeEncodedFile

> Use BOM encoding for non-ASCII files

`powershell/PSUseBOMForUnicodeEncodedFile` is a PSScriptAnalyzer diagnostic emitted by tally for PowerShell snippets embedded in Dockerfiles.

| Property | Value             |
| -------- | ----------------- |
| Severity | Warning           |
| Category | PSScriptAnalyzer  |
| Default  | Disabled in tally |
| Auto-fix | No                |

<Note>
  tally disables this rule by default because Dockerfile `RUN` bodies are inline strings, not
  files on disk with encoding metadata. Re-enable it with
  `include = ["powershell/PSUseBOMForUnicodeEncodedFile"]` or by setting
  `rules.powershell.PSUseBOMForUnicodeEncodedFile.severity = "warning"` in `.tally.toml`.
</Note>

## Description

For a file encoded with a format other than ASCII, ensure Byte Order Mark (BOM) is present to ensure
that any application consuming this file can interpret it correctly.

You can use this rule to test any arbitrary text file, but the intent is to ensure that PowerShell
scripts are saved with a BOM when using a Unicode encoding.

## How

For PowerShell commands that write to files, ensure that you set the encoding parameter to a value
that produces a BOM. In PowerShell 7 and higher, the following values of the **Encoding** parameter
produce a BOM:

* `bigendianunicode`
* `bigendianutf32`
* `oem`
* `unicode`
* `utf32`
* `utf8BOM`

When you create a script file using a text editor, ensure that the editor is configured to save the
file with a BOM. Consult the documentation for your text editor for instructions on how to save
files with a BOM.

## Further reading

For more information, see the following articles:

* [about\_Character\_Encoding](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_character_encoding)
* [Set-Content](https://learn.microsoft.com/powershell/module/microsoft.powershell.management/set-content)
* [Understanding file encoding in VS Code and PowerShell](https://learn.microsoft.com/powershell/scripting/dev-cross-plat/vscode/understanding-file-encoding)

## Source

This rule documentation is adapted from Microsoft's PSScriptAnalyzer documentation for
[UseBOMForUnicodeEncodedFile](https://github.com/MicrosoftDocs/PowerShell-Docs-Modules/blob/main/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseBOMForUnicodeEncodedFile.md),
licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).
