PowerShell uses variables to store information that can be useful later on. Variables also make it easy to change values in multiple places by changing the variable’s definition. You can store information such as names, paths, and the results of commands in a variable.

As you become more fluent in PowerShell, the idea of variable scope is likely to start playing a part in writing scripts, functions, and modules. In this post, I will cover the basics of PowerShell variable scope and provide examples of how to use scoping in PowerShell scripts and modules.

Check out the full article over at the Varonis Inside Out Security Blog:
PowerShell Variable Scope Guide: Using Scope in Scripts and Modules