Skip to content

Files

Latest commit

 

History

History
37 lines (27 loc) · 1.02 KB

UseSupportsShouldProcess.md

File metadata and controls

37 lines (27 loc) · 1.02 KB

Pattern: Missing use of SupportsShouldProcess

Issue: -

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

Example of incorrect code:

function test {
    param(
        $param1,
        $confirm,
        $whatif
    )
}

Example of correct code:

function test {
    [CmdletBinding(SupportsShouldProcess)]
    param(
        $param1
    )
}

Further Reading