Export (0) Print
Expand All
Expand Minimize
2 out of 2 rated this helpful - Rate this topic

Converting VBScript's Option Explicit Statement

Windows PowerShell

Definition: Forces explicit declaration of all variables in a script.

Option Explicit

In VBScript, the Option Explicit statement forces you to declare all variables before using them in a script. To do the same thing in Windows PowerShell use the Set-PSDebug Cmdlet and the -strict parameter, like so:

set-psdebug -strict

What will that do for you? Well, suppose you now try to execute a command similar to this, using the uninitialized variable $z:

$a = 2 + $z

You won’t get an answer; instead you’ll get the following error message:

The variable $z cannot be retrieved because it has not been set yet.

To turn off this behavior, use this command:

set-psdebug -off

Return to the VBScript to Windows PowerShell home page

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.