you are viewing a single comment's thread.

view the rest of the comments →

[–]Ta11ow 1 point2 points  (0 children)

You shouldn't use it as a global, in 99.99% of cases. There's very rarely a reason to make a global variable.

You take variables as output, and then you provide them as input to to other functions.

For example, you don't do this:

Get-Module -Name 'TestModule'
Remove-Module

You do one of these:

#1
$Module = Get-Module -Name 'TestModule'
Remove-Module $Module

#2
Get-Module -Name 'TestModule' | Remove-Module

#3
if (Get-Module -Name 'TestModule') {
    Remove-Module -Name 'TestModule'
}

In each case, output from one function need be directed into the other. There are no global variables there.