We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script repository

Preserve user creation initiator

December 04, 2024 Views: 26

The script saves the initiator of the target user creation to a predefined property. To execute the script, create a custom command configured for the required object type.

In the script, the $initiatorPropertyName variable specifies the schema name of the DN-syntax property to preserve user creaton initiator in. If the target object was created outside Adaxes, the property will be cleared.

Edit Remove
PowerShell
$initiatorPropertyName = "adm-CustomAttributeObject1" # TODO: modify me

# Get user modification log.
$modificationLog = $Context.TargetObject.GetModificationLog()
$log = $modificationLog.Log
$records = $log.GetPage(0)

foreach ($record in $records)
{
    $operationTypes = $record.GetOperationTypes()
    if ($operationTypes -notcontains "create")
    {
        continue
    }

    try
    {
        # Get initiator DN.
        $initiator = $Context.BindToObject($record.Initiator.AdsPath)
        $initiatorDN = $initiator.Get("distinguishedName")
    }
    catch
    {
        $initiatorDN = $NULL
    }
    
    break
}

# Save changes
$Context.TargetObject.Put($initiatorPropertyName, $initiatorName)
$Context.TargetObject.SetInfo()
Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers