Skip to main content

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/PSUseShouldProcessForStateChangingFunctions is a PSScriptAnalyzer diagnostic emitted by tally for PowerShell snippets embedded in Dockerfiles.
PropertyValue
SeverityWarning
CategoryPSScriptAnalyzer
Auto-fixNo

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

function Set-ServiceObject
{
    [CmdletBinding()]
    param
    (
        [string]
        $Parameter1
    )
    ...
}

Correct code

function Set-ServiceObject
{
    [CmdletBinding(SupportsShouldProcess = $true)]
    param
    (
        [string]
        $Parameter1
    )
    ...
}

More information

Source

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