0 votes

I'm attaching below a snippet from a scheduled task. It's a function that receives as a parameter the employeeID, which is then used in the search filter. There is definitely a user with that employeeID but the message is indicating that No employee with that ID is found. Any assistance would be greatly appreciated as we are under an extreme time constraint to get this resolved.

function SearchUser ($employeeId, $properties)
{
    $Context.LogMessage("Inside SearchUser - EmployeeID = $employeeId", "Information")
    $searcher = $Context.BindToObjectEx("Adaxes://rootDSE", $True)
    $domainControllerFQDN = $searcher.Get("dnsHostName")
    $Context.LogMessage($domainControllerFQDN, "Information")
    $searcher.SearchScope = "ADS_SCOPE_SUBTREE"
    $searcher.SearchFilter = "(&(sAMAccountType=805306368)(employeeID=$employeeId))"
    #$searcher.SearchFilter = "(employeeID=$employeeId)"
    $searcher.PageSize = 500
    $searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
    $searcher.SetPropertiesToLoad($properties)
    $searcher.VirtualRoot = $True

    try
    {
        $searchResultIterator = $searcher.ExecuteSearch()
        $searchResults = $searchResultIterator.FetchAll()
    }
    finally
    {
        $searchResultIterator.Dispose()
    }

    $userInfo = $NULL
    if ($searchResults.Length -eq 0)
    {
        # The user account does not exist
        $Context.LogMessage("A user with employee ID " + $employeeId + " does not exist in AD", "Warning")
    }
    elseif ($searchResults.Length -igt 1)
    {
        # More than one user account exists with this UID
        $Context.LogMessage("Multiple users were returned for employee ID " + $employeeID , "Warning")
    }
    else
    {
        $userInfo = @{}
        $searchResult = $searchResults[0]
        $userInfo.AdsPath = $searchResult.AdsPath
        foreach ($propertyName in $properties)
        {
            $userInfo."$propertyName" = $searchResult.Properties[$propertyName].Value
        }
    }

    return $userInfo
}
by (870 points)
0

I should also add that the search needs to look in multiple domains. That's why I'm attempting to use rootDSE instead of some of the other methods I've seen documented.

1 Answer

0 votes
by (301k points)
selected by
Best answer

Hello,
You need to change the following line in your script

$searcher = $Context.BindToObjectEx("Adaxes://rootDSE", $True)

to

$searcher = $Context.BindToObjectEx("Adaxes://rootDSE", $False)

Related questions

0 votes
1 answer

I have an export that will run as a monthly scheduled task that will write output to a CSV to contain employees that have been ... ([datetime]terminationDate>=$lastMonth))" $properties = $eachFieldIn $userSearcher.SetPropertiesToLoad($properties)

asked Nov 2, 2015 by sandramnc (870 points)
0 votes
1 answer

Looking for a script (unless there is a built in way, which I don't think there is) to grant User A full access to User B's OneDrive

asked Dec 16, 2024 by msheppard (790 points)
0 votes
1 answer

Hi, I'm very new to Adaxes and still getting to grips with it. Is there any way to search or filter within the web interface, users that have an Exchange Online shared mailbox? Thanks

asked Oct 14, 2020 by sysg89 (20 points)
0 votes
0 answers

In 2025.1 on the web interface, Entra AD no longer appears as a managed domain, though our local AD still functions correctly. Entra users can still be found via search, but ... Entra AD Please also note this was working before the update to 2025.1 from 2023.2

asked Apr 15 by Biagi_IT (20 points)
0 votes
1 answer

I gone throught Adaxes License is based and its based on user. I wanted to understand, does the license user count is on technical assistance user or AD objects?

asked Jan 23, 2020 by subbu (20 points)
3,679 questions
3,361 answers
8,506 comments
549,394 users