> ## 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/PSAvoidOverwritingBuiltInCmdlets

> Avoid overwriting built in cmdlets

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

| Property | Value            |
| -------- | ---------------- |
| Severity | Warning          |
| Category | PSScriptAnalyzer |
| Auto-fix | No               |

## Description

This rule flags cmdlets that are available in a given edition/version of PowerShell on a given
operating system which are overwritten by a function declaration. It works by comparing function
declarations against a set of allowlists that ship with PSScriptAnalyzer. These allowlist files are
used by other PSScriptAnalyzer rules. More information can be found in the documentation for the
[UseCompatibleCmdlets][01] rule.

## Configuration

To enable the rule to check if your script is compatible on PowerShell Core on Windows, put the
following in your settings file.

<Note>
  tally forwards matching `rules.powershell.PSAvoidOverwritingBuiltInCmdlets` options to PSScriptAnalyzer.
</Note>

```powershell theme={null}
@{
    'Rules' = @{
        'PSAvoidOverwritingBuiltInCmdlets' = @{
            'PowerShellVersion' = @('core-6.1.0-windows')
        }
    }
}
```

### Parameters

#### PowerShellVersion

The parameter `PowerShellVersion` is a list of allowlists that ship with PSScriptAnalyzer.

<Note>
  In upstream PSScriptAnalyzer, the default value for `PowerShellVersion` is `core-6.1.0-windows` if PowerShell 6 or later is installed, and
  `desktop-5.1.14393.206-windows` if it is not. tally itself requires `pwsh` 7.x as the analyzer host and does not support `powershell.exe` or Windows
  PowerShell 5.1 as the host process.
</Note>

Usually, patched versions of PowerShell have the same cmdlet data, therefore only settings of major
and minor versions of PowerShell are supplied. One can also create a custom settings file as well
with the [New-CommandDataFile.ps1][02] script and use it by placing the created `JSON` into the
`Settings` folder of the `PSScriptAnalyzer` module installation folder, then the `PowerShellVersion`
parameter is just its filename (that can also be changed if desired). Note that the `core-6.0.2-*`
files were removed in PSScriptAnalyzer 1.18 since PowerShell 6.0 reached end of life.

[01]: /rules/powershell/PSUseCompatibleCmdlets

[02]: https://github.com/PowerShell/PSScriptAnalyzer/blob/main/Utils/New-CommandDataFile.ps1

## Source

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