How to Create and Use an Object Browser In PowerShell
Introduction
This is a PowerShell application which displays objects in an explorer style user interface. The PowerShell source code for this object browsing application is available in the gallery (PowerShell Object Browser). The PowerShell Object Browser displays the properties and child objects / collections for any PowerShell / .Net framework object. It also shows the information returned by Get-Member cmdlet at the click of a mouse as well as shows the .Net Framework class interface as returned by Get-Type cmdlet for the object instance selected.
A PowerShell prompt has been provided so that PowerShell statements can be processed while the application is running and objects can be dynamically added to / removed from the object browser.
A number of object trees have been built-in for cmdlets such as Get-Command, Get-Module, Get-Variable, Get-Process and Get-Service. These object trees are select-able by a View menu item.
https://social.technet.microsoft.com/Forums/getfile/570391
How it works
The object browser queries the members of the object and only displays the properties (no methods) that do not have any parameters. It queries the return type of the property to determine if a child node on the tree is required. Within the Options menu, are menu options to control what is displayed in the tree. (This is explained in greater detail in a later section).
Objects are queried in a generic fashion and there is no attempt to identify the object type and query it specifically. Once the property has been called, the return type is checked to determine it's type. Basically, there are three categories of return types that determine placement within the object browser; a value type, an object and a collection.
Value types are booleans, numbers, strings and enums and are only displayed on the instance tab that lists the property values. No child tree nodes are produced for the value type properties. Objects can appear on the instance tab and/or as child tree nodes as controlled by the Options menu. Collections always appear as child tree nodes.
Since the objects are queried generically, it relies on the designer / implementer of the objects for what is displayed. The child objects and collections will be auto populated in the tree. Collection properties that return a few thousand objects will display in a reasonable amount of time (depends on CPU speed).
The Tabs
The content of some tabs is related to what is selected in the tree. In the explanations for each of the tabs, the same object will be shown to demonstrate the different context of each of tabs, the object shown will be the form object of the object browser.
The Instance Tab
The instance tab is related to what is selected in the tree. This tab lists the property values of the object selected in the tree. Values that are shown or not are determined by the Options menu.
The Class Tab
The class tab is related to what is selected in the tree. This tab lists the members that are returned by the Get-Member cmdlet.
The Interface Tab
The interface tab is related to what is selected in the tree. The tab show the type returned by the Get-Type cmdlet. It is a mini object browser by itself showing the properties and collections of the type. It also lists all the types in the inheritance tree.
The PSObject Tab
The PSObject tab is related to what is selected in the tree. This tab provides a template for defining the properties for a PSObject based on the object selected. The template can then be copied into a script.
The Values Tab
The values tab is related to what is selected in the tree. This tab provides the values of the properties based on the object selected. The values can then be copied.
The PowerShell Tab
The PowerShell tab provides a PowerShell prompt so that PowerShell statements can be processed while the application is running and objects can be dynamically added to / removed from the object browser. It uses the $ExecutionContext.InvokeCommand.InvokeScript(Script) method to process the script and displays the output. The script is entered in the top and then click the Execute button and the output is displayed in the bottom.
It will handle the pipeline;
It also handles functions, for example;
There are limitations in terms of variable scope and the output, it is not meant to be a total replacement for the PowerShell command prompt. The main usefulness is to dynamically add and remove objects to the object browser. A method has been defined to add nodes to the tree, with the following syntax;
Add-Node Object Text
In this example, it adds the VMHost object to the tree using the Get-VMHost cmdlet and the result is assigned to the $Node variable and then the $Node variable is then displayed.
The output is what is returned from the $ExecutionContext.InvokeCommand.InvokeScript(Script) method call. The variable goes out of scope as this is occurring within a function call. (Note: statements can be commented out)
Edited the script and clicked the execute button to test if the $Node variable is null;
The Add-Node function will add the object to the tree and returns the tree node. A reference to this tree node is only required if the tree node is to be removed later on in the session using the Remove-Node function otherwise it is not necessary to assign Add-Node to a variable. Since the variable goes out of scope, it is necessary to declared the variable as a $Script variable.
The node can now be removed using the Remove-Node function.
The WMI Classes Tab
The WMI Class tab provides the area where to input the computer name and filter for the Win32 Classes.
The View Menu
A number of object trees have been built-in for cmdlets such as Get-Command, Get-Module, Get-Variable, Get-Process and Get-Service. These object trees are select-able by a View menu item. Menus that are checked indicates that selection is present in the tree.
The Options Menu
The options menus control what child items of the selected object are shown in the tree and in the property list.
The Object Browser profile
Within the event handler for the Form_Load event, it calls a Get-PSObjectBrowserProfile function. This function is located conveniently at the top of the script file so that it can be easily found and edited. This function can call menu click events to customize the object browser environment and auto load objects.