Script sample to use with Run | Unsupported Script rule
Summary: This article describes how to use the Run | Unsupported Script rule to run the external script.
Applies to: Cayosoft Administrator 5.4.0 or later
Get and set properties of a user created with New User web action
In the Cayosoft Administrator Console, create a new Run | Unsupported Script rule.
In the Script File setting, specify the file with the following PowerShell script. Set attributeLdapName for modification and set log path as needed:
-
Copy
# Get objectGUID of created object
$CreatedObjectGUID = (GetSessionParameter "CreatedObjectGUID")
if($CreatedObjectGUID -eq $null) {
# Incorrect script execution context
Write-Error "Incorrect script execution context: target object GUID is NULL."
return;
}
# Get created object DN using objectGUID
$CreatedObjectDN = (LookupGuidByMapTable $CreatedObjectGUID $defaultParams)
# Get correct AD DC where object was created
$defaultDCParams = (PMEXTAD_GetSettingsAsParamsEx $AD_DefaultDC $AD_Credentials)
$correctDCParams = (PMEXTAD_GetADSettingsByDN -ObjectDN $CreatedObjectDN -DefaultDC $AD_DefaultDC -Credential $AD_Credentials)
# Get properties of created user
$createdUser = Get-ADUser -Identity $CreatedObjectDN -Property * @correctDCParams
#Set some property value on created user
Set-ADUser -Identity $CreatedObjectDN -Replace @{"attributeLdapName"="attributeValue"} @correctParams
# Write debug information to a log file
[System.IO.File]::AppendAllText("C:\Logs\testlog.txt", "$(Get-Date): Script completed succesfully!`n") Make sure that the Use separate process setting is set to No.
Click Save changes.
Navigate to Configuration > Web Portal > Web Actions.
Click Active Directory > New User Web Action.
Add created Run | Unsupported script rule to the Rules to run after this rule section in the New User action.
Get and set properties of a user updated with User Properties web action
-
Perform steps 1-4 from the previous section, using this script:
Copy# Get objectGUID of Updated object
$UpdatedObjectGUID = $CayoSelectedObjectsIds[0].ObjectId
if($UpdatedObjectGUID -eq $null) {
# Incorrect script execution context
Write-Error "Incorrect script execution context: target object GUID is NULL."
return;
}
# Get Updated object DN using objectGUID
$UpdatedObjectDN = (LookupGuidByMapTable $UpdatedObjectGUID $defaultParams)
# Get correct AD DC where object was Updated
$defaultDCParams = (PMEXTAD_GetSettingsAsParamsEx $AD_DefaultDC $AD_Credentials)
$correctDCParams = (PMEXTAD_GetADSettingsByDN -ObjectDN $UpdatedObjectDN -DefaultDC $AD_DefaultDC -Credential $AD_Credentials)
# Get properties of Updated user
$UpdatedUser = Get-ADUser -Identity $UpdatedObjectDN -Property * @correctDCParams
# Set properties on Updated user
Set-ADUser -Identity $UpdatedObjectDN -Replace @{"attributeLdapName"="attributeValue"} @correctParams
# Write debug information to a log file
[System.IO.File]::AppendAllText("C:\Logs\testlog.txt", "$(Get-Date): Script completed succesfully!`n") Navigate to Configuration > Web Portal > Web Actions.
Click Active Directory > Properties (of Active Directory user) Web Action.
-
Perform the step 6 from the previous section for the User Properties web action.
NOTE: The Run | Unsupported Script rule can be linked to any Web Action.
Get and set properties of a user created with Runbook
-
Perform steps 1-4 from the previous section, using this script:
Copy$CreatedObjectDN = (GetSessionParameter "CreatedADUsersDNs")
if(-not ($CreatedObjectDN -is [array])){ $CreatedObjectDN = @($CreatedObjectDN) }
$CreatedObjectDN | %{ $objectDN = $_;
$correctDCParams = (PMEXTAD_GetADSettingsByDN -ObjectDN $objectDN -DefaultDC $AD_DefaultDC -Credential $AD_Credentials)
$createdUser = Get-ADUser -Identity $objectDN -Property * @correctDCParams
Set-ADUser -Identity $objectDN -Replace @{"attributeLdapName"="attributeValue"} @correctDCParams
} Navigate to Runbook in which you need to add the unsupported script run.
Click Link to existing.
Select the Unsupported script rule.
Click Ok.
Save changes.
Comments
0 comments
Please sign in to leave a comment.