Edit

AvoidShouldContinueWithoutForce

Severity Level: Warning

Description

This rule detects functions that use ShouldContinue without a boolean Force parameter. Functions that use ShouldContinue should have a boolean Force parameter to allow users to bypass the confirmation prompt.

When using ShouldContinue in advanced functions, call it after the ShouldProcess method returns $true.

To learn more, see about_Functions_CmdletBindingAttribute and about_Functions_Advanced_Methods.

Example

Noncompliant

Function Test-ShouldContinue
{
    [CmdletBinding(SupportsShouldProcess=$true)]
    Param
    (
        $MyString = 'blah'
    )

    if ($PsCmdlet.ShouldContinue('ShouldContinue Query', 'ShouldContinue Caption'))
    {
        ...
    }
}

Compliant

Function Test-ShouldContinue
{
    [CmdletBinding(SupportsShouldProcess=$true)]
    Param
    (
        $MyString = 'blah',
        [Switch]$Force
    )

    if ($Force -or $PsCmdlet.ShouldContinue('ShouldContinue Query', 'ShouldContinue Caption'))
    {
        ...
    }
}