Skip to content

Files

Latest commit

 

History

History
51 lines (38 loc) · 850 Bytes

AvoidDefaultValueSwitchParameter.md

File metadata and controls

51 lines (38 loc) · 850 Bytes

Pattern: Use of default value switch parameter as $True

Issue: -

Description

Switch parameters for commands should default to false.

How

Change the default value of the switch parameter to be false.

Example of incorrect code:

function Test-Script
{
    [CmdletBinding()]
    Param
    (
        [String]
        $Param1,

        [switch]
        $Switch=$True
    )
    ...
}

Example of correct code:

function Test-Script
{
    [CmdletBinding()]
    Param
    (
        [String]
        $Param1,

        [switch]
        $Switch=$False
    )
    ...
}

Further Reading