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 (790 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 (220k 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 (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
1 answer

Our adaxes service account is able to create the mailbox when running our create user business rule, but cannot change any settings like disable OWA. What level of security will it need?

asked Apr 6, 2021 by bstone (50 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)
0 votes
0 answers

Hello, When I click on a user from the web interface I get this error message at the top of the page : The search filter cannot be recognized. (Server: domainname) Before ... one for service desk). What can I do to troubleshoot and find out the cause? thanks.

asked Apr 29, 2016 by tentaal (1.1k points)
2,733 questions
2,469 answers
6,460 comments
1,336,406 users