Script Actions
From PowerGUI Wiki
Contents |
Adding script actions
Script actions, unlike nodes and links, can have parameters. To set up parameters simply enter param[keyword]($name).
To implement an action
- In the Actions pane, select Add new item | Script Action.
- Enter the input collection code ($input) to populate the objects.
Links/actions associated with a node
You can associate actions and links with the node rather than with the real object type. 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
This provides more flexibility than just associating with a node, because you can re-use the same type label in other nodes and links if you want them to share the same set of Links and Actions with the original.
What are smart controls for script actions?
PowerGUI allows you to prompt the user for parameter input inside of script actions. You can also provide smart controls that will recognize the type of the parameter and provide appropriate options.
For example, suppose you wanted to create a script action which would require the user to provide a true or false value to decide what the action was going to do. You could do this with the following script:
- prompt the user for the parameter value
param([bool]$doYouLikeIceCream)
- rest of action script
if ($doYouLikeIceCream -eq $true) { eat-iceCream } else { eat-lowFatSoyMilkDairyDessert }
In this script, since you specifically identified the type of the $doYouLikeIceCream parameter as a boolean value, PowerGUI will give you a drop-down control to specify true or false for that value when it prompts you with the parameter dialog box. The drop-down control is the Smart Control for the script action.
Note: Ensure that your param statement is the first executable statement in the script.
Implementing changes through actions
Once you have the required set of objects, you are ready to affect change through actions. Actions are associated with a specific object class. For example, the available actions for a user are not the same as those available for a group.
To implement a change
1. Select the objects where you want to affect change.
2. Click the required action from the list.
3. Locate the required parameter, change the value, and click OK.
The action is executed and the update is immediately displayed in the console.
Smart Parameter Controls - Whenever possible, PowerGUI provides a rich control instead of a default edit box. This includes Booleans, enumerations, dates, and arrays.
Performing common actions
Common actions, such as reporting, exporting, and importing, are not tied to a specific object class and therefore are the same for all objects.
Creating reports
Once you have filtered and sorted the data to suit your needs, you can save the information in an XML, CSV, or HTML file, or simply copy it to the clipboard.
You can create a report of all the objects or only select objects. The report includes only the objects that you selected, with the properties displayed in the same sorted order as in the console.
