The script generates a report containing user accounts disabled during the specified number of days. For information on creating reports, see the Create report tutorial.
In the script, the $daysParamNumber specifies the name of the report parameter used to select the number of days. The parameter can be of the Drop-down (item values should contain the number of days to check for) or Edit box (only integer values allowed) type. The parameter name should be specified with the param- prefix.
PowerShell
$daysParamNumber = "param-MyParam" # TODO: modify me
$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)