Search notes:

PowerShell: create a global variable in a function

Without using scope modifiers, a non-global variable that is used within a function creates the variable for the scope of the function.
Sometimes, there is a requirement to create a (global) variable within a function. This can be achieved by prefixing the variable name with global::
function create-global-var() {

   $global:num = 42
   $global:txt ='Hello world'

}
Github repository about-PowerShell, path: /language/variable/create-global-var-in-func.ps1

Index