Just thought I’d blog about PowerShell variable scope. It seems that not many people are aware of this (I wasn’t aware until recently). There are scopes for private, local (this is the default behaviour), script and global (the PowerShell console).
$private:myVar = “Some value”
$local:myVar = “Some value”
$script:myVar = “Some value”
$global:myVar = “Some value”
This article contains a nice section with slightly more detail. http://powershell.com/cs/blogs/ebookv2/archive/2012/02/02/chapter-3-variables.aspx#scope-of-variables