0 votes

We have 3 email domains. 1 primary and 2 subsidary companies.

I'm needing to automate setting the email domain during user creation based on department. See attached screenshot.Screenshot 2025-03-07 090927.png

I'm unable to get this working correctly and would like to see if we could get it working.

I also need to be able to automate this for ongoing maintenance if users move between departments.

ago by (20 points)
0

Hello,

Sorry for the confusion, but we are not sure what exactly you need to achieve. Please, describe the desired behavior in all the possible details with live examples.

0

Sorry, I guess I submitted this mid thought.

The issue happens when we run the create user action with the actions above, the process doesn't work. It seems to be trying to modify the email domain in exchange using the old incoorect User Login Name and it never actually works correctly.

Screenshot 2025-03-07 094702.png

0

Hello,

We do not see any issues in your screenshot. The action worked exactly as configured. It just took the value of the Username (schema name userPrincipalName) property and set it as primary SMTP address. Also, you did not provide any insights on how the workflow should actually depend on the user department.

0

As you can see it, sets the User Logon Name to end in @riggsrents.com but when the final workflow runs, it sets it to @riggscat.com. Those should match. It should be setting the user logon name to @riggsrents.com based on department "Cat Rental Store".

The 2 steps later it should modify the mailbox setting to add the @riggsrents.com domain and set it as primary. This is the part that's not working correctly. Its adding the @riggsrents.com domain based on policy.

this is how it looks when finished via the exchange server. Screenshot 2025-03-07 101644.png

Here is the exchange address policy that's being applied: Screenshot 2025-03-07 101804.png

I think the underlying issue is that when the action runs, it is using the old %userPrincipalName% instead of the new one, Screenshot 2025-03-07 101850.png

1 Answer

0 votes
ago by (299k points)

Hello,

Your assumption is correct and the behavior is by design. The thing is that value references resolve before the entire business rule is executed. As such, no matter what changes you make to the username property in the rule, value reference %username% will resolve into the value existing before all those actions execution.

To achieve the desired, you need to set the username properly. It has to be unique forest wide and thus should not be updated the way you do it. It should be done using a script in a business rule triggering Before creating a user. In this case, the value reference used to set the email address will work as you expect. The following tutorial will be helpful: https://www.adaxes.com/help/ValidateModifyUserInputWithScript.

0

Well I guess that makes sense. I have the below script that runs before user creation and works great outside of choosing the secondary email domains.(this is new to us, we used to only use a single email domain) . Can you assist with what I would need to change in order for this to work as expected?

function BuildUsername()
{
    $samAccountNameBuilder = New-Object "System.Text.StringBuilder"
    for ($i=0; $i -lt $args.length; $i++)
    {
        if (-not($args[$i] -is [array]))
        {
            if (-not([System.String]::IsNullOrEmpty($args[$i])))
            {
                [void]$samAccountNameBuilder.Append($args[$i].ToLower())
            }
        }
        elseif ($args[$i].length -eq 3) 
        {
            if (-not([System.String]::IsNullOrEmpty($args[$i][0])))
            {
                $valueLength = $args[$i][1]
                if ($valueLength -gt $args[$i][0].Length)
                {
                    $valueLength = $args[$i][0].Length
                }

                switch ($Args[$i][2])
                {
                    "Beginning"
                    {
                        $value = $args[$i][0].SubString(0,$valueLength).ToLower()
                    }
                    "End"
                    {
                        $value = $args[$i][0].SubString($args[$i][0].Length - $valueLength).ToLower()
                    }
                }
                [void]$samAccountNameBuilder.Append($value)
            }
        }
        else
        {
            $Context.LogMessage("An error occurred while building a username!", "Error")
        }
    }

    return $samAccountNameBuilder.ToString()
}

Import-Module Adaxes

function IsUserNameUnique($username)
{
    $user = Get-AdmUser $username -erroraction silentlycontinue
    return $user -eq $Null
}

function SetUsername($samAccountName, $domainName)
{
    # Update samAccountName
    $Context.SetModifiedPropertyValue("samAccountName", $samAccountName)

    # Update userPrincipalName
    $userPrincipalName = $samAccountName + "@" + $domainName

    $Context.SetModifiedPropertyValue("userPrincipalName", $userPrincipalName)

    # Inform the user
    $Context.LogMessage("User Logon Name (pre-Windows 2000) has been changed to: $samAccountName", "Information")
    $Context.LogMessage("User Logon Name has been changed to: $userPrincipalName", "Information")
}

# Get the username and domain name
$username = $Context.GetModifiedPropertyValue("samAccountName")
$domainName = "%username:format[domain]%"

if ([System.String]::IsNullOrEmpty($domainName))
{
    $domainName = $Context.GetObjectDomain("%distinguishedName%")
}

# Check whether the username is already unique
if (IsUserNameUnique($username))
{
    return
}

# Try building a unique username automatically

# Use Last Name and initial characters of the First Name 
$firstName = $Context.GetModifiedPropertyValue("givenName")
$lastName = $Context.GetModifiedPropertyValue("sn")
for ($i = 2; $i -le $firstName.Length; $i++)
{
    $uniqueUsername = BuildUsername $lastName @($firstName, $i, "Beginning")
    # Check if the username is unique
    if (IsUserNameUnique($uniqueUsername))
    {
        # Update username and exit script
        SetUsername $uniqueUsername $domainName
        return
    }
}

# Failed to generate a unique username. Cancel creation of the new user
$Context.Cancel("Failed to generate a unique username. You need to input a unique username manually.")
0

Hello,

You need to add a specific logic to the script that will call the SetUsername function with the required domain name (second parameter). Unfortunately, we cannot be more specific as we have no information on the desired behavior.

Related questions

0 votes
1 answer

We have a single AD domain that also matches our primary email domain (e.g. @primarydomain.com), but we also have multiple company specific email domains (e.g. @companydomain. ... like to also link the companydomain.com to the user's company value set in AD.

asked Apr 29, 2020 by JacquesKruger (20 points)
0 votes
1 answer

Hi: I am trying to create a business rule that will stop a value change based on the existing value. For example, if the telephonenumber is 1234 for a group and has to ... the value it uses is the incoming value of the change, not the existing value. Thanks!

asked Jun 3, 2022 by crobitaille (80 points)
0 votes
0 answers

We are in hybrid mode with 365. All the accounts we create have to made with a .com instead of .local. How can I make that change in adaxes? Or is this some default I need to change in AD instead?

asked Apr 11, 2022 by LEGIT1 (150 points)
0 votes
1 answer

During the creation of a new user I want to be able to select the job title from a drop-down list which populates different values based on which Department is selected. Is there a way to achieve this? Thanks. Dario.

asked Oct 2, 2020 by winstonsmith (40 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)
3,648 questions
3,336 answers
8,432 comments
548,983 users