Powershell Best Practice #9: Use custom folding regions

By | May 22, 2015

Best Practice: It is recommended to use region statement to split your code into logicial parts (ex: variables, functions, etc.)

region-expand--and-collapse

Explanation: Since PowerShell v3, ISE supports code folding (feature of some editors/IDEs that allows the user to hide/display some “fold” sections).

In english, the verb “fold” means:

folding

So, you can fold/unfold  by clicking the + / – sign on the left side.

Regions are used to collapse/expand custom blocks of code you define and makes the code easier to read and to navigate.

Note: “region” and “endregion” are case sensitive (lower case required).

Tip: To expand/collapse in Powershell ISE : Control + M


previous-buttonnext-button

One thought on “Powershell Best Practice #9: Use custom folding regions

  1. Pingback: Powershell Best Practice #8: Use WhatIf and Confirm parameters | Powershell Guru

Leave a Reply

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