Summary: There are situations when some script or command-line utility need to be executed as a result of Web UI command execution. This article provide a step-by-step guidance on adding a script execution rule to the web action rule execution chain.
Applies to: Cayosoft Administrator 5.X or later.
Important: Running custom scripts and external command-line tools from within Cayosoft Administrator may lead to performance degradation, unpredictable behavior, incompatibility issues or data corruption. The compatibility of the script with the Cayosoft Administrator and target system behavior is a sole responsibility of the customer. Note that external script and command-line tool need to be tested with each upgrade of Cayosoft Administrator.
Prepare a script to run after Web UI command
When running a script after some command is executed in the Web UI, the script often needs to identify the object being selected by the user for the command.
There are 2 variables you can use in your script to identify an object selected for the command:
- $CayoSelectedObjectsIds.ObjectDN - the Active Directory Distinguished Name of the object, if the object was selected in one of AD web queries
- - the Active Directory object GUID for object selected in AD web query, or Azure AD object ID for object selected in the Office 365 web query
See the Script Sample section below.
Note: only PowerShell scripts (*.ps1) could be run by Cayosoft Administration Service. If you have a script, written in other language, or a cmdline utility to run, you can create a PowerShell script that will run your custom script or cmdline utility. See this article for help: PowerShell: Running Executables.
Create and configure 'Run | Unsupported Script' rule
- Run Cayosoft Administrator console
- In the top left corner click the +New button and select Rule
- Search for 'Run | Unsupported Script' template, select it and click Next
- To search for the rule, click the Show all templates link and enter 'run' in the search box
- Select "Do nothing" for the Rule Output and click Next
- Provide a name and folder for the rule and click Finish
- Configure the Action section settings:
- Click [..] button next to the Script file setting and select your script file (*.ps1)
- IMPORTANT: If you need to identify the object being selected in the Web UI for the web command, switch the Use separate process setting to "No".
- Click Save Changes to save the rule
Link the 'Run | Unsupported Script' rule to the web action rule
- In the Cayosoft Administrator Console, navigate to the HOME > CONFIGURATION > Web Interface > Web Actions > Active Directory
- Select the web action rule, after which you want to run your script
- For example, select the Rename User web action rule
- Enable editing in Design Mode, see the KB20180730-1 for details
- Go to Action tab and expand the Rules to run after this rule section
- Click the Add button under the Specify Rules to run list view and select the 'Run | Unsupported Script' rule, created in the previous step
- Click Save Changes to save the web action rule
This script sample would add a line of text to the CayoRunScriptRule.txt file, located in the c:\Test1\ folder. Text would contain timestamp, selected object DN and ID.
$ObjectDN = $CayoSelectedObjectsIds.ObjectDN $ObjectGuid = $CayoSelectedObjectsIds.ObjectId $date = Get-Date -Format FileDateTime "[$date] Object DN: $ObjectDN; Object GUID: $ObjectGuid" | Out-File -Append -FilePath "c:\Test1\CayoRunScriptRule.txt"