Script Nodes
From PowerGUI Wiki
Adding script nodes
To add a script node
1. Right-click the PowerGUI node and select New | Script Node.
2. Enter a name for the script.
3. Enter your PowerShell script and click OK.
Whatever object your script emits get displayed in the PowerGUI grid.
Setting grid object type
PowerGUI admin console is choosing which links/actions to display based on the type of the first object your node/link emits to the grid.
Sometimes you might want to force PowerGUI into displaying a specific actions for a specific node. The easiest way to do this is to mark the output of a node as your custom type by applying this code to the objects the node outputs:
$myObject.PSObject.TypeNames.Insert(0,'MyObjectTypeName')
See this article for more information: Essential PowerShell: Name your custom object types
Implementing dynamic trees
Dynamic trees handle dynamic data and allow you to browse hierarchies such as file systems, OUs, and public folders. Each time you select the node, its script is executed.
To implement dynamic trees
• Follow this sample as you design the root dynamic node (the one which would generate subnodes on the fly):
# declare a custom function which PowerGUI would use to get the list of nodes
# try to make the name unique to avoid conflicts with other trees,
# use the parameter set which is applicable
function global:CreatePublicFolderChildNode($obj)
{
# this is how you get the currently selected node
$cur = [quest.powergui.hostfactory]::current.application.navigation.currentitem;
# AddChild function adds a subnode and gives you the object back so you can set the label and the code
$ch = $cur.AddChild();
# Set the label
$ch.Name = $obj.Name;
# Set the code to be executed in case user clicks this new node
$ch.Script = 'Get-PublicFolder ' + $obj.Identity + ' -GetChildren | foreach { CreatePublicFolderChildNode $_ }'
# Return the object back so it gets into the grid as well
$obj
}
# This is the code that gets you the root item and starts the tree-building process by calling the function.
Get-PublicFolder -GetChildren | foreach { CreatePublicFolderChildNode $_}
