Establish and enforce coding rules in expressions, scripts, and script blocks.

      Set-StrictMode -Off [CommonParameters]

      Set-StrictMode -Version Version [CommonParameters]

       Turn strict mode off.
       This parameter also turns off "Set-PSDebug -Strict".

    -Version Version
       The conditions that cause an error in strict mode. (Required)

       valid values:

        1.0        Prohibit references to uninitialized variables,
                   except for uninitialized variables in strings.

        2.0        Prohibit references to uninitialized variables (including uninitialized variables in strings).
                   Prohibit references to non-existent properties of an object.
                   Prohibit function calls that use the syntax for calling methods.
                   Prohibit a variable without a name (${}).
        Latest     Select the latest (most strict) version available.
                   Use this value to assure that scripts use the strictest
                   available version, even when new versions are added to PowerShell.

       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
       -OutBuffer -OutVariable.

With strictmode set to 2.0 calling a function with myfunct(2,4) instead of the correct myfunct 2 4 will throw an error "The function or command was called like a method. Parameters should be separated by spaces"


Turn strict mode on and set it to version 1.0:

PS C:\> set-strictmode -version 1.0

C:\PS> $a -gt 5
The variable $a cannot be retrieved because it has not been set yet.
At line:1 char:3

Turn off strictmode (this is the default):

PS C:\> set-strictmode -off

“You are already of consequence in the world if you are known as a man of strict integrity” ~ Grenville Kleiser

Related PowerShell Commands:

Set-PSdebug - Turn script debugging on or off
Equivalent bash command: cd - Change Directory

Copyright © 1999-2019
Some rights reserved