0 votes

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.

by (100 points)

1 Answer

0 votes
by (14.1k points)

Hello,

First of all, the script executed in the business rule triggering Before creating a user must be updated to use criteria instead of an LDAP filter. Additionally, since the VirtualRoot property is set to $True, you can set the searcher to the target object. Please, find the updated script below. Should you still face errors executing the script, please, provide a screenshot of the Create user operation execution log. You can post the screenshot here or send us at support@adaxes.com.

# Build criteria
$criteria = New-AdmCriteria -Type "user" -Expression {sAMAccountName -eq "%username%" -or mail -eq "%username%@domain.gov" -or proxyaddresses -eq "smtp:%username%@domain.gov"}

# Search for users with the username or email address specified
$searcher = $Context.TargetObject
$searcher.Criteria = $criteria
$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()
}
0

Thanks for the script. I updated the business rule with the script you provided and received the same error as before. Here is the execution log of the business rule with the updated script.

2024-09-05 12_47_45-Log Record Properties.png

Here is the execution log of the create user (note that the creation was sucessful because the line it's throwing the exception on is prior to the search results length check).

2024-09-05 12_52_59-Log Record Properties.png

0

Hello,

Thank you for the provided details. For further troubleshooting, please, do the following:

  • Provide us with a screenshot of the Multi-server environment dialog. The dialog displays how many Adaxes services you have and what their versions are. For information on how to view it, see https://www.adaxes.com/help/MultiServerEnvironment.
  • Clarify whether the Microsoft Entra domain mentioned in the error is managed by Adaxes.
  • Specify where the user is created, in an on-premises domain or in a Microsoft Entra domain.

Related questions

0 votes
1 answer

Using this built in function: There is no option to change the domain on the user account, however this is not the domain we use for UPN. However after creating a user, you can change it but trying to avoid going back into the object.

asked Apr 14, 2023 by mightycabal (1.0k points)
0 votes
1 answer

Is there a way to have the Create User trigger to run a command to trigger the update user flag/trigger to be hit? The goal is to have specific Create User tasks to also go through the same tasks as the Update user.

asked Mar 2, 2023 by mobosys (290 points)
0 votes
1 answer

I need a way of triggering a business rule based on the user (and not the group) being added or removed from a group. The reason I would like this triggered on the user is so ... prefer not to do that. I am checking to see if there is another way to do this.

asked May 16, 2023 by mark.it.admin (2.3k points)
0 votes
1 answer

Currently, when I disable a user account in Adaxes, the group memberships of the user remain intact. I'd like to automate the removal of group memberships such as distribution ... a list of groups/DL that the user was previously in and removed from. Thanks!

asked Nov 3, 2021 by jayden.ang (20 points)
0 votes
1 answer

Hello, is there a way to automatically create a user after creating a user in a different domain? Let me explain: We have a Management Domain we own and a new ... be created automatically We got a adaxes service account in both domains. Thanks in advance!

asked May 14, 2019 by Redfruit (100 points)
3,548 questions
3,239 answers
8,232 comments
547,814 users