Powershell Best Practice #11: Use Set-StrictMode in your dev scripts

By | June 7, 2015

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.

Here we can see we get an error as the variable $i has not been set.

powershell set strictmode latest version

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.


Leave a Reply

Your email address will not be published.