O'Reilly logo

Windows PowerShell™ 3.0 Step by Step by Ed Wilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Enabling strict mode

One easily correctable problem that can cause debugging nightmares in a script involves variables. Variables are often used incorrectly, are nonexistent, or are initialized improperly. An easy mistake to make when using variables is a simple typing error. Simple typing errors can also cause problems when contained in a large complex script. Enabling strict mode causes Windows PowerShell to display an error if a variable is not declared. This helps you to avoid the problem of nonexistent or improperly initialized variables.

Using Set-PSDebug -Strict

An example of a simple typing error in a script is shown in the SimpleTypingError.ps1 script.

SimpleTypingError.ps1

$a = 2 $b = 5 $d = $a + $b 'The value of $c is: ' + $c ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required