I would like to know the scope of the variable $crazy in the following PowerShell script:
function Test1 {
Write-Host $crazy
}
function Main {
$crazy = Read-Host "Type anything"
Test1
}
Main
I was expecting $crazy to be only visible within Main function but, to my surprise, the function Test1 was able to access it. I can guarantee that there's no previously declared $crazy variable in my PS session.
I'll be honest I didn't fully understand about_scope so I used ISE to debug through the script and tested the scope of the variable with the following pattern $<scope>:$crazy and the variable didn't even appear every scope I've used.
$crazyis local tofunction Main{...}, and can only be seen/read fromTest1because you call it from insideMain