I have a scheduled task that runs the following PowerShell script.
$user = New-AdmUser -Server $domain -AdaxesService localhost -Path $workdayDn -ChangePasswordAtLogon $true -PassThru -GivenName $firstName -Surname $lastName -Department $department -Manager $managerDn -OtherAttributes $otherAttributes
The script runs under the context of domain\account.
There is an existing business process rule that triggers before user is created that runs the following script to verify that the username and email are unique within our environment. Note this script does work appropriately when manually creating a user. This script also runs under the context of domain\account.
# Build search filter
$filter = "(&(sAMAccountType=805306368)(|(sAMAccountName=%username%)(mail=%username%@domain.gov)(proxyaddresses=smtp:%username%@domain.gov)))"
# Search for users with the username or email address specified
$searcher = $Context.BindToObject("Adaxes://rootDSE")
$searcher.SearchFilter = $filter
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.PageSize = 500
$searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
$searcher.VirtualRoot = $True
$searcher.SizeLimit = 1
try
{
$searchResultIterator = $searcher.ExecuteSearch()
$searchResults = $searchResultIterator.FetchAll()
if ($searchResults.Length -ne 0)
{
$Context.Cancel("A user with the same username or email address already exists. Please choose a different username.")
return
}
}
finally
{
# Release resources
$searchResultIterator.Dispose()
}
When the scheduled task runs to create the user via PowerShell, the user business process rule keeps throwing the following error:
Exception calling "FetchAll" with "0" argument(s): "Object 'domain.onmicrosoft.com' does not exist." Stack trace: at <ScriptBlock>, <No file>: line 26
I understand that the business process rule searches all domains in Adaxes based on the virtual root being set to true. The domain it is complaining about is our M365 tenant. I am thinking it's a permissions issue, but have already verified that the account that runs both PowerShell scripts (BP and Schelued task) has full control (Super Manager role) over all objects.
I'm stumped! Any help would be super appreciated.