Script repository
The script generates a report containing user accounts disabled during the specified period. To execute the script, create a report with a parameter of the Drop-down (item values should only contain the number of days to check for) or Edit box (only integer values allowed) type. The report should have no scope.
In the script, the $daysParamNumber variable specifies the name of the report parameter used to select the number of days. The parameter name should be specified with the param- prefix.
$daysParamNumber = "param-MyParam" # TODO: modify me
# Get parameter value.
$days = $Context.GetParameterValue($daysParamNumber)
# Bind to the directory object representing the General Log.
$path = $Context.GetWellKnownContainerPath("ServiceLog")
$serviceLog = $Context.BindToObject($path)
$generalLog = $serviceLog.GeneralLog
if ($days -ne 0)
{
$generalLog.StartDateTime = (Get-Date).AddDays(-$days)
$generalLog.EndDateTime = Get-Date
}
# Get the log records.
$log = $generalLog.Log
$records = $log.GetPage(0)
# Build filter to search for disabled users.
$guidComparer = $Context.CreatePropertyValueComparer("objectGuid")
$guids = New-Object System.Collections.Generic.HashSet[byte[]] @($guidComparer)
foreach ($record in $records)
{
if ($Context.Items.Aborted)
{
return
}
if (($record.TargetObjectType -ne "user") -or ($record.TargetObjectGuid -eq $NULL))
{
continue
}
$operationTypes = $record.GetOperationTypes()
if ($operationTypes -notcontains "disable account")
{
continue
}
# Get GUID
$guidBytes = ([Guid]$record.TargetObjectGuid).ToByteArray()
$guids.Add($guidBytes)
}
$searcher = $Context.CreateGuidBasedSearcher(@($guids))
$searcher.Criteria = New-AdmCriteria -Type "user" -Expression {accountDisabled -eq $true}
$Context.Items.Add($searcher)
Comments 0
You must be signed in to comment.