ISE Addons, PowerShell, vNext
comment 1

PowerShell ISE Addon: ISE Function Explorer using the PowerShell 3.0 parser

Last month, I wrote here about an ISE addon that used PowerShell psparser and Out-GridView cmdlet to show all the functions available in a script in PowerShell ISE. After that, Jason Shirk — a language developer — from the PowerShell team pointed to some PowerShell 3.0 beauty – the new language parser.

NOTE: The following code works only with PowerShell 3.0 RC and later.

Thanks to Jason, here is the new ISE function explorer code:

This is how the new function explorer looks.

Function Explorer

Function Explorer

Look at the number of lines in the above code and how easy it is to get a list of functions in my module. This is possible because of the improvements to the PowerShell parser in 3.0. The ParseInput() method takes the script contents as input and returns ScriptBlockAst as the output.

AST refers to Abstract Syntax Tree []

Once we have the output from the parser, we can use FindAll() method to search only for the function definitions by specifying FunctionDefinitionAst as the predicate.

The FunctionDefinitionAst represents both functions and filters. The second parameter on the FindAll() method decides if nested script blocks should be included or not. So, by setting this to $false, we can avoid listing the nested function definitions in the ISE function explorer.

This is it. More on the capabilities of the parser later!

Filed under: ISE Addons, PowerShell, vNext


Ravikanth is a principal engineer and the lead architect for Microsoft and VMware virtualized and hybrid cloud solutions within the Infrastructure Solutions Group at Dell EMC. He is a multi-year recipient of Microsoft Most Valuable Professional (MVP) award in Windows PowerShell (CDM) and Microsoft Azure. Ravikanth is the author of Windows PowerShell Desired State Configuration Revealed (Apress) and leads Bangalore PowerShell and Bangalore IT Pro user groups. He can be seen speaking regularly at local user group events and conferences in India and abroad.

  • Great post! The AST is a great addition to the PowerShell toolkit!