Script repository

Recently enabled users with initiator

Updated on: Jan 18, 2026, Views: 1135

Reports, Logging

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

The report will only include user accounts that are currently enabled.

Parameters

  • $daysParameterName - the name of the parameter used to determine the period (in days) during which users were enabled. The name should be specified with the param- prefix.
  • $dateColumnID - the identifier of the custom column that will contain the date when a user was enabled. The column should be of the Date/Time 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.
  • $initiatorColumnID - the identifier of the custom column that will contain the user who enabled the corresponding account. The column should be of the Directory object type.
$daysParameterName = "param-Days" # TODO: modify me
$dateColumnID = "{99287f6e-af75-4588-af77-4eb88df8ba9e}" # TODO: modify me
$initiatorColumnID = "{96639d74-841e-4622-86f8-295a5672c399}" # 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)

# Search parameters
$guidToInitiator = @{}
$guidComparer = $Context.CreatePropertyValueComparer("objectGuid")
$guidsToSearch = New-Object System.Collections.Generic.HashSet[byte[]] @($guidComparer)

foreach ($record in $records)
{
    if ($Context.Items.Aborted)
    {
        return
    }
    
    if ($record.TargetObjectType -ne "user")
    {
        continue
    }
    
    $guid = [Guid]$record.TargetObjectGuid
    if ($guidToInitiator.ContainsKey($guid))
    {
        continue
    }
    
    $operationTypes = $record.GetOperationTypes()
    if ($operationTypes -notcontains "enable account")
    {
        continue
    }

    # Get GUID
    $adsPath = New-Object "Softerra.Adaxes.Adsi.AdsPath" $record.Initiator.AdsPath
    $customColumns = @{
        $initiatorColumnID = $adsPath.DN
        $dateColumnID = $record.CompletionTime
    }
    
    $guidToInitiator.Add($guid, $customColumns)
    $guidsToSearch.Add($guid.ToByteArray())
}

# Search criteria
$searcher = $Context.CreateGuidBasedSearcher(@($guidsToSearch))
$criteria = New-AdmCriteria -Type "user" -Expression {accountDisabled -eq $false}
$searcher.AddCriteria($criteria)
$searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"

try
{
    $searchIterator = $searcher.ExecuteSearch()
    while ($Context.MoveNext($searchIterator))
    {
        $searchResult = $searchIterator.Current
        $guid = [Guid]$searchResult.GetPropertyByName("objectGuid").Values[0]
        $customColumns = $guidToInitiator[$guid]
        $Context.Items.Add($searchResult, $customColumns)
    }
}
finally
{
    # Release resources
    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.