Summary: Check for undeclared variables.
How can I cause the script to generate an error if a variable has not been declared?
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