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
}