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 that require an authentication token, such as a REST web service:
function Connect-Service {
[CmdletBinding()]
param (
[Parameter...