Using Code Regions in ISE

by Feb 20, 2015

PowerShell 3.0 and later

PowerShell ISE already supports collapsible code regions. When you write functions, loops, or conditions, you will notice a vertical line in the left margin with a “minus” symbol on top. Click it to collapse the region.

If regions are missing, you may have to enable them: View/Show Outlining.

You can use regions and code folding for other parts of your script, too. To enclose an arbitrary part of your code in a collapsible region, put special comments into your code:

#region Variable Declarations
$a = $b = $c = 1
$d, $e, $f = 2,3,4
#endregion 

Note that these special comments are case sensitive. The text following “#region” becomes the title of the collapsible region once you collapse it.

Twitter This Tip! ReTweet this Tip!