Best Practice: It is recommended to use Set-StrictMode for your development scripts to identify code issues.
It is the equivalent of the well known “Option Explicit” in VBS and useful to avoid to enforce coding rules (undeclared variables, etc.) and prevent some common scripting errors.
Set-StrictMode -Version Latest
Here we can see we get an error as the variable $i has not been set.
Using “Set-StrictMode” will avoid you to waste some debugging time (to investigate unexpected results) and reduce bugs.
The parameter -Version is the most strict.
It is recommended to use Set-StrictMode during the development but not in production scripts.
Note: Set-StrictMode is turned off by default.