The script can be used to generate a report that will include disabled user accounts that are managers of enabled user accounts. For information on creating reports, see the Create Report tutorial.
PowerShell
$criteria = New-AdmCriteria "user" -Expression {(directReports -empty $False) -and (accountDisabled -eq $True)}
$Context.DirectorySearcher.AddCriteria($criteria)
$Context.DirectorySearcher.SearchParameters.PropertiesToLoad.Add("distinguishedName")
try
{
$searchIterator = $Context.DirectorySearcher.ExecuteSearch()
$managerDNToSearchResult = @{}
while ($Context.MoveNext($searchIterator))
{
$searchResult = $searchIterator.Current
$managerDNToSearchResult.Add($searchResult.GetPropertyByName("distinguishedName").Values[0], $searchResult)
}
}
finally
{
# Release resources
if ($searchIterator) { $searchIterator.Dispose() }
}
# Search parameters
$searcher = New-Object Softerra.Adaxes.Adsi.Search.DirectorySearcher $NULL, $False
$searcher.VirtualRoot = $True
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
$searcher.Criteria = New-AdmCriteria "user" -Expression {(manager -empty $False) -and (accountDisabled -eq $False)}
$searcher.PageSize = 500
$searcher.SetPropertiesToLoad(@("manager"))
try
{
# Execute search
$searchIterator = $searcher.ExecuteSearch()
while ($Context.MoveNext($searchIterator))
{
$searchResult = $searchIterator.Current
$managerDN = $searchResult.GetPropertyByName("manager").Values[0]
if ($managerDNToSearchResult.ContainsKey($managerDN))
{
$managerSearchResult = $managerDNToSearchResult[$managerDN]
$managerDNToSearchResult.Remove($managerDN)
$Context.Items.Add($managerSearchResult)
}
}
}
finally
{
# Release resources
if ($searchIterator) { $searchIterator.Dispose() }
}
The issue occurs because you are using Adaxes 2023 or later while the script was written for Adaxes 2021.1. To achieve the desired, use the below script. We also updated the script in the article itself.