PowerShell Variable Scope

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>