ISE Script Organisation

by k7842 at 2013-01-10 13:02:47

Hi All,

First post! Yay!

I hope you guys can help me! I’ve been tearing my hair out over this one…

I want a way to organise my sections of code within the ISE console so that I can minimise and maximise areas of script even where you would not normally need brackets etc.

Let me give you an example to better explain:

I have currently:


CLS
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

# Adds The Microsoft Exchange Management Snap-In

CLS
Write-Host "Hello. I need stuff to write here..." # Splash Screen
Write-Host "Press any key to continue..."
$null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp,AllowCtrlC") # Press Any Key To Continue...

# Splash Screen Completed

# Etc...


I would like it to appear as:


{...} # Adds The Microsoft Exchange Management Snap-In

{...} # Splash Screen Completed

# Etc...


When I do this by adding the brackets to give that lovely organised "+" sign on the left of the ISE, it breaks the script and doesn’t run correctly.

PLEASEE HELP!

Thank you in advance!

Adam
by ArtB0514 at 2013-01-10 13:32:52
There is a solution to this issue, but you need to be using at least Quest’s PowerGUI or PowerShell 3.0 ISE (other third parties probably support this, but I don’t know for sure).

#region >>Any optional descriptive text<<
# your script elements go here
#endregion >>Can repeat descritive text here, too, if you want<<

When collapsed (<CTRL>m in PS3), you will see this in the ISE, preceeded with a + sign:
#region >>Any optional descriptive text<<…
by nohandle at 2013-01-11 03:18:59
As ArtB0514 said it works in both PowerGUI and PowershellISE 3.0. There is one but: The ISE accepts it only in the lowercase form #region. Not #Region or anything else. The PGUI does not care.