Summary: There are situations when some script or command-line utility needs to be executed as a result of Web UI command execution. This article provides step-by-step guidance on adding a script execution rule to the web action rule execution chain.
Applies to: Cayosoft Administrator 9.x or later.
ID: KB20180911-1
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 the sole responsibility of the customer. Note that the external script and command-line tool need to be tested with each upgrade of the 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[0].ObjectDN - the Active Directory Distinguished Name of the object, if the object was selected in one of AD web queries
- $CayoSelectedObjectsIds[0].ObjectId - the Active Directory object GUID for the object selected in the AD web query, or Azure AD object ID for the 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 another 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 the '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 the [..] 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 Home > Configuration > Web Portal > 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 the Action tab and expand the Rules to run after this rule section
- Click the Add button under the Specify Rules to run the list view and select the 'Run | Unsupported Script' rule, created in the previous step
- Click Save Changes to save the web action rule
Script sample
This script sample would add a line of text to the CayoRunScriptRule.txt file, located in the c:\Test1\ folder. The text would contain a timestamp, selected object DN, and ID.
$ObjectDN = $CayoSelectedObjectsIds[0].ObjectDN
$ObjectGuid = $CayoSelectedObjectsIds[0].ObjectId
$date = Get-Date -Format FileDateTime
"[$date] Object DN: $ObjectDN; Object GUID: $ObjectGuid" | Out-File -Append -FilePath "c:\Test1\CayoRunScriptRule.txt"
Comments
0 comments
Please sign in to leave a comment.