Module scope
The content of the root module file executes when a module is imported. Functions are imported into the module scope and exported into global scope if they are included in the list of functions to export.
Variables may be created in the module scope, functions within the module may consume those variables. Such variables might be created in the root module, or they may be created when a command is run.
The $Script: scope prefix may be used to explicitly access the scope and it clearly identifies such variables where they are used. Helper functions might be created to provide obvious access to the variable content.
This approach is illustrated in the following example. This pattern is common for modules that interact with services ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access