Skip to main content
powershell/PSUseShouldProcessForStateChangingFunctions is a PSScriptAnalyzer diagnostic emitted by tally for PowerShell snippets embedded in Dockerfiles.
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/PSUseShouldProcessForStateChangingFunctions"] or by setting rules.powershell.PSUseShouldProcessForStateChangingFunctions.severity = "warning" in .tally.toml.

Description

Functions whose verbs change system state should support ShouldProcess. To enable the ShouldProcess feature, set the SupportsShouldProcess argument in the CmdletBinding attribute. The SupportsShouldProcess argument adds Confirm and WhatIf parameters to the function. The Confirm parameter prompts the user before it runs the command on each object in the pipeline. The WhatIf parameter lists the changes that the command would make, instead of running the command. Verbs that should support ShouldProcess:
  • New
  • Set
  • Remove
  • Start
  • Stop
  • Restart
  • Reset
  • Update

How

Include the SupportsShouldProcess argument in the CmdletBinding attribute.

Examples

Problematic code

Correct code

More information

Source

This rule documentation is adapted from Microsoft’s PSScriptAnalyzer documentation for UseShouldProcessForStateChangingFunctions, licensed under CC BY 4.0.