July 15th, 2015

PowerTip: Find References to Uninitialized Variables in PowerShell

Doctor Scripto
Scripter

Summary: Easily find references to uninitialized variables in Windows PowerShell.

Hey, Scripting Guy! Question My extremely long script keeps failing and I suspect it may be because of variables that are not
           initialized prior to being used. How can I find uninitialized variables?

Hey, Scripting Guy! Answer Use the Set-StrictMode cmdlet and set it to –version 1 to ensure that all references to 
           initialized variables generate an error:

Set-StrictMode –version 1

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