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 (294k 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 by msheppard (660 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)
3,589 questions
3,278 answers
8,303 comments
548,107 users