Search code examples
powershellpowershell-3.0

Collapse or toggle 1 region in the PowerShell ISE


It there a way to programmatically collapse 1 region (ONLY ONE!) in a PowerShell script. I'd like to deliver a script with a region of dependencies collapsed. I can use dot sourcing to save someone viewing the script from having to scroll through the function dependencies but it would be nice to be able to deliver the script in 1 file.

Example of what I'm trying to accomplish.

$psISE.CurrentFile.Editor.ToggleOutliningExpansion('*function dependencies*')
#region -- function dependencies ---...

#Everything else in the script is expanded and viewable.
Function Invoke-MainFunction()
{}

Solution

  • Unfortunately this isn't possible. The ToggleOutliningExpansion() method only has a single method signature. That method signature takes zero parameters.

    enter image description here

    I'd highly recommend posting this feature enhancement request on the UserVoice page, where the PowerShell core team accepts feedback though! Here's a direct link to it: https://windowsserver.uservoice.com/forums/301869-powershell