Hello, I currently have a working script that lists out ALL users disabled in the last 30 days. I am trying to adjust the parameter to ONLY include subordinates of a certain person or filter by departments. I'm assuming the script is taking precedence, so the parameter isn't working. Am I able to adjust it through the report options in Adaxes, or how would I alter the script? Is there an easier way to do this? TIA
Current script:
$days = 30
# 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)