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 (288k 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

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

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
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

base dn: OU=Users,DC=domain,DC=com then we have sub OU's like OU=Department,OU=Users,DC=domain,DC=com and OU=Site,OU=Department,Dc=domain,dc=com i would like to filter all the users inside base dn.

asked Feb 21, 2023 by dppankib (20 points)
3,538 questions
3,229 answers
8,224 comments
547,747 users