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.
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()