Chapter 5. Scope

Like the previous chapter, this chapter may be a bit of a refresher. But because the concept of scope continues to trip people up, we feel it’s worth our time and yours to get on the same page. More than likely your toolmaking projects will be on the complex side, and if you don’t understand scope, you may end up with a bad tool.

5.1. What is scope?

Scope is a system of containerization. In some senses, it’s designed to help keep things in PowerShell from conflicting with one another. For example, if you ran a script that defined a variable named $x, you’d be pretty upset if some other script also used $x and somehow messed up your script. Scope is a way of building walls between and around different scripts and functions, ...

Get Learn PowerShell Toolmaking in a Month of Lunches now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.