September 9th, 2012

PowerTip: Two Quick Ways to Check Variables in PowerShell

Doctor Scripto
Scripter

Summary: Check for undeclared variables.

Hey, Scripting Guy! Question How can I cause the script to generate an error if a variable has not been declared?

Hey, Scripting Guy! Answer Here are a couple of ways to do this with Windows PowerShell.

a. Place set-psdebug –strict anywhere in the script. Any nondeclared variable will generate an error when accessed.

b. Use Set-StrictMode –Version latest

 

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.

Feedback