PowerShell

PowerShell: Enabling Strict Mode

PowerShell is very forgiving of errors. For example, if you call something that does not exist, then no error message is displayed. In this short article I want to show you how to make PowerShell a bit more strict with the strict mode.

Consider you are calling a variable that doesn’t exist. PowerShell will display no errors.

Another example. Why is it showing true? $a doesn’t exist.

With strictmode mode, however, PowerShell will return an error. First we need to enable it.

Set-StrictMode -Version Latest

Now PowerShell will display an error: “The variable ‘$a’ cannot be retrieved because it has not been set.

That was what I wanted to show. Have fun with PowerShell.

Categories: PowerShell

Tagged as: ,

3 replies »

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.