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

> Use SupportsShouldProcess

`powershell/PSUseSupportsShouldProcess` 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 for Dockerfile `RUN` snippets because a `RUN` executes
  statements inline rather than defining cmdlets, parameters, or modules with external callers. Re-enable it with
  `include = ["powershell/PSUseSupportsShouldProcess"]` or by setting
  `rules.powershell.PSUseSupportsShouldProcess.severity = "warning"` in `.tally.toml`.
</Note>

## Description

This rule discourages manual declaration of `WhatIf` and `Confirm` parameters in a function/cmdlet.
These parameters are, however, provided automatically when a function declares a `CmdletBinding`
attribute with `SupportsShouldProcess` as its named argument. Using `SupportsShouldProcess` not only
provides these parameters but also some generic functionality that allows the function/cmdlet
authors to provide the desired interactive experience while using the cmdlet.

## Examples

### Problematic code

```powershell theme={null}
function foo {
    param(
        $param1,
        $Confirm,
        $WhatIf
    )
}
```

### Correct code

```powershell theme={null}
function foo {
    [CmdletBinding(SupportsShouldProcess)]
    param(
        $param1
    )
}
```

## Source

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