This tutorial will explain how to add custom actions to Automation Machine. To add a custom package action, the first thing we will do is to extend the action menu for packages with a custom action.
- Create a new folder in %am_files%\config\actions called package
- Create a file called package.xml in %am_files%\config\actions
<Actions> <Action> <Script>Custom-PackageAction.ps1</Script> <Name>Custom Package Action</Name> <Icon>icon.png</Icon> <PowerShellArguments>-noexit</PowerShellArguments> </Action> </Actions>
Note 1: The XML is case sensitive
Note 2: The PowerShell arguments are the arguments for powershell.exe, in this example -noexit is used to prevent PowerShell automatically closing after invoking the script. For more arguments run powershell.exe -?
- Create the Custom-PackageAction.ps1 in config\actions\package
Param ( [array]$ObjectIDs ) ForEach ($ObjectID in $ObjectIDs) { $Package = Get-AMPackage -Id $ObjectID Write-Host $Package.Name }
Note 1: The AM Admin module is automatically loaded for the custom action scripts.
Note 2: AM provides an array of objectIDs to the custom script, so the custom script should be able to deal with this array.
- Add the icon.png icon in %am_files%\config\actions
- Start the AM user interface, and navigate to a package. You should now see your custom action.
- Click the action and you should have output like this
Adding other custom actions
You can repeat the same steps to add custom actions for the following:
- Collections (use config\actions\collection folder for icons and scripts and config\actions\collection.xml for defining the actions)
- Note: These actions are available for all collections, regardless of their collection type
- Layers (use config\actions\layer folder for icons and scripts and config\actions\layer.xml for defining the actions)
- Dashboard (use config\actions\dashboard folder for icons and scripts and config\actions\dashboard.xml for defining the actions)
- Note: These actions are available for all computers, regardless of the collection type of the collection they belong to
Adding custom action for specific collection types (only for version 1.3.48 and higher)
Sometimes you want to add a custom action in collection or dashboard view that is only valid for a certain type of collection. This can be achieved by appending the collection type GUID to the folder names and xml files.To get a list of collectiontype's run the following in an AM Admin API powershell session:
# Show all collection typesGet-AMCollectionType# Get Id for XenApp session host collection type(Get-AMCollectionType | ? {$_.Name -eq "XenApp Session Host"}).Id.ToString()
Hint: If Get-AMCollectionType is not a valid command, try to use Get-AMEventMap
To add actions to collection view that are only valid for XenApp Session host we would have to create the following:
- new folder: config\actions\collection-ad72845c-e87f-451a-b0bb-9d4328f2b8b9
- new file: config\actions\collection-ad72845c-e87f-451a-b0bb-9d4328f2b8b9.xml
For dashboard it's the same, just add dashboard-ad72845c-e87f-451a-b0bb-9d4328f2b8b9 folder and dashboard-ad72845c-e87f-451a-b0bb-9d4328f2b8b9.xml file.