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

> Use compatible cmdlets

`powershell/PSUseCompatibleCmdlets` 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 aren't available in a given Edition and Version of PowerShell on a
given Operating System. It works by comparing a cmdlet against a set of allowlists which ship with
PSScriptAnalyzer. They can be found at `/path/to/PSScriptAnalyzerModule/Settings`. These files use
the `<psedition>-<psversion>-<os>.json` form, where `<psedition>` can be either `Core` or `Desktop`,
`<os>` can be either `Windows`, `Linux` or `macOS`, and `<psversion>` is the PowerShell version. 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.PSUseCompatibleCmdlets` options, such as `compatibility`, to PSScriptAnalyzer.
</Note>

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

The parameter `compatibility` is a list that contains any of the following:

* desktop-2.0-windows
* desktop-3.0-windows
* desktop-4.0-windows (taken from Windows Server 2012R2)
* desktop-5.1.14393.206-windows
* core-6.1.0-windows (taken from Windows 10 - 1803)
* core-6.1.0-linux (taken from Ubuntu 18.04)
* core-6.1.0-linux-arm (taken from Raspbian)
* core-6.1.0-macos

The `desktop-*` values are upstream PSScriptAnalyzer compatibility targets, not tally analyzer host support. tally runs the analyzer through
PowerShell 7 (`pwsh`); Windows PowerShell 5.1 (`powershell.exe`) is out of scope as a sidecar host.

Usually, patched versions of PowerShell have the same cmdlet data, therefore only settings of major
and minor versions of PowerShell are supplied. You can also create a custom settings file with the
[New-CommandDataFile.ps1][01] script. Place the created `.json` file in the `Settings` folder of the
`PSScriptAnalyzer` module folder. Then the `compatibility` parameter value is just the filename.
Note that the `core-6.0.2-*` files were removed in PSScriptAnalyzer 1.18 since PowerShell 6.0
reached its end of life.

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

## Source

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