Script repository

Recently created users with initiator

Updated on: Jan 18, 2026, Views: 1555

Reports, Logging

The script generates a report of recently created users with initiator. If a user was created outside of Adaxes, the initiator column will be empty. To execute the script, create a report with corresponding custom column and parameter. The report must have a scope.

Parameters

  • $daysParameterName - the name of the parameter used to determine the period (in days) to retrive created users for. The name should be specified with the param- prefix.
  • $columnID - the identifier of the custom column that will contain the user who created the corresponding account. The column should be of the Directory object type. To get the identifier of a custom column:
    • In the Report-specific columns section, on the Columns tab, right-click the custom column.
    • In the context menu, navigate to Copy and click Column ID.
    • The column identifier will be copied to clipboard.
$daysParameterName = "param-Days" # TODO: modify me
$columnID = "{3345fe9c-9c7d-43ab-9aee-92fb041d9091}" # TODO: modify me

# Get parameter values
$days = $Context.GetParameterValue($daysParameterName)

# Bind to the directory object representing the General Log.
$path = $Context.GetWellKnownContainerPath("ServiceLog")
$serviceLog = $Context.BindToObject($path)

$generalLog = $serviceLog.GeneralLog
$generalLog.StartDateTime = (Get-Date).AddDays(-$days)
$generalLog.EndDateTime = Get-Date

# Get the log records.
$log = $generalLog.Log
$records = $log.GetPage(0)

$guidToInitiator = @{}

foreach ($record in $records)
{
    if ($Context.Items.Aborted)
    {
        return
    }
    
    if (($record.TargetObjectType -ne "user") -or ($record.TargetObjectGuid -eq $NULL) -or ([Guid]$record.TargetObjectGuid -eq [Guid]::Empty))
    {
        continue
    }
    
    $operationTypes = $record.GetOperationTypes()
    if ($operationTypes -notcontains "create")
    {
        continue
    }

    # Get GUID
    $guid = [Guid]$record.TargetObjectGuid
    $guidToInitiator.Add($guid, $record.Initiator.Adspath)
}

$threshold = (Get-Date).AddDays(- $days)
$thresholdGeneralizedTime = [Softerra.Adaxes.Utils.Transform]::ToGeneralizedTime($threshold.ToUniversalTime())

# Search criteria
$criteria = New-AdmCriteria "user" -Expression {whenCreated -ge $thresholdGeneralizedTime}
$Context.DirectorySearcher.AddCriteria($criteria)

try
{
    $searchIterator = $Context.DirectorySearcher.ExecuteSearch()
    while ($Context.MoveNext($searchIterator))
    {
        $searchResult = $searchIterator.Current
        $guid = [Guid]$searchResult.GetPropertyByName("objectGuid").Values[0]
        
        $customColumns = @{$columnID = $guidToInitiator[$guid]}
        $Context.Items.Add($searchResult, $customColumns)
    }
}
finally
{
    if ($searchIterator) { $searchIterator.Dispose() }
}

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    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.