August 29th, 2014

PowerTip: Hide Common Code in PowerShell ISE

Doctor Scripto
Scripter

Summary: Learn how to hide common code in the Windows PowerShell ISE.

Hey, Scripting Guy! Question How can I hide related code in the Windows PowerShell ISE to make it easier to troubleshoot and to read?

Hey, Scripting Guy! Answer Open the ISE, and in the script pane, begin a section with the #Region tag and a name.
           Then end the section with the #EndRegion tag. Now everything between the two tags can be collapsed
           and hidden when desired. Here is an example:

#region Name

 If($d.name -match  ‘,’)

        {

          $name = (Get-Culture).textinfo.ToTitleCase($d.name).Split(‘,’).trim()

          $ln = $name[0]

          $fn = $name[1]

          }

#endregion

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.