Scopes are important in your day-to-day scripting and they control the visibility of your variables, functions, and aliases. While PowerShell does a great job of handling scopes automatically in a way that feels very natural to the user, you can also use scopes implicitly in your scripts.
Variable scoping
How to do it...
Install and start PowerShell Core and execute the following steps:
- Execute the following code block:
$outerScope = 'Variable outside function'
function Foo
{
Write-Host $outerScope
$outerScope = 'Variable inside function'
Write-Host $outerScope
}
Foo
Write-Host $outerScope
You should see the following output:
- Modify the code a little bit to use scope modifiers like private, script...