Establish and enforce coding rules in expressions, scripts, and script blocks.
Syntax
Set-StrictMode -Off [CommonParameters]
Set-StrictMode -Version Version [CommonParameters]
Key
-Off
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.
CommonParameters:
-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"
Examples
Turn strict mode on and set it to version 1.0:
PS C:\> set-strictmode -version 1.0
C:\PS> $a -gt 5
False
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:
Set-PSdebug - Turn script debugging on or off
Equivalent bash command: cd - Change Directory
© Copyright SS64.com 1999-2013
Some rights reserved