0 votes

I made a script that changes the username if such a name is already taken, set up a business rule before user create as written in the instructions http://www.adaxes.com/help/ValidateModifyUserInputWithScript/, but when you try to create an account, an error appears that such an object already exists, while before that the rule for changing the name worked Error: Business Rules: 1 rule encountered while processing your request 'Check for unique': Run PowerShell script 'Check for unique' for the user The username has been changed to teadaxes@domain.com. The object already exists on 'domain.com:636'.

by (100 points)

1 Answer

0 votes
by (294k points)

Hello,

The thing is that Active Directory does not allow creating users with the same Full Name in the same OU. This is something that can be adjusted in a script same like the username. For an example, have a look at Example 3 – Rename the user if the Full Name is not unique within the OU in the following tutorial: https://www.adaxes.com/help/ValidateModifyUserInputWithScript.

0

I create an account in another ou, where there are no duplicates, but still an error. I tried to check for duplicates in one OU, also an error! Screenshot 2022-11-21 112625.png Script:

Import-Module Adaxes

function IsUserNameUnique($username)
{
    $domain = $Context.GetObjectDomain("%distinguishedName%")
    $user = Get-AdmUser -Filter {userPrincipalName -eq $username}  -Server $domain -AdaxesService localhost
    return $null -eq $user
}

$username = $Context.GetModifiedPropertyValue("userPrincipalName")
$firstname = $Context.GetModifiedPropertyValue("givenName")
$lastname = $Context.GetModifiedPropertyValue("sn")

if (IsUserNameUnique($username))
{
    return
}

$localPart, $domainPart = $username.Split("@")
$uniqueUsername = $Null
for ($i = 1;; $i++)
{
    $uniqueUsername = $firstname.Substring(0, $i) + $lastname + "@" + $domainPart
    if (IsUserNameUnique($uniqueUsername))
    {
        $samAccountName = $firstname.Substring(0, $i) + $lastname
        break
    }
}

$Context.SetModifiedPropertyValue("userPrincipalName", $uniqueUsername)
if ($Context.IsPropertyModified("sAMAccountName"))
{
    $Context.SetModifiedPropertyValue("sAMAccountName", $samAccountName)
}

$Context.LogMessage("The username has been changed to " + $uniqueUsername + ".", "Information")
0

Hello,

The error about existing object is returned by Active Directory and is not related to Adaxes. Are you sure that there are no accounts in the OU with the same Name/Full Name? You r script does not check that. If you are checking in Adaxes, the existing duplicate can be in unmanaged list and not displayed when browsing AD. Please, try checking in AD itself (e.g. using Active Directory Users and Computers).

Related questions

0 votes
1 answer

We want to check, if the number of a new team (group) is unique. The number is stored in the attribute "gidNumber". I have a business rule executing before creating ... $NULL) { $Context.Cancel("Ein Team mit dieser Team-Nummer existiert bereits!") return } }

asked Oct 13, 2020 by lohnag (160 points)
0 votes
1 answer

Hi, I'd like to implement a rule to ensure that telephoneNumber value is unique accross the domain for each user, either after creation or updates. I tried to implement a ... one (before change). How to get the new value in the script ? Thanks Stephen

asked May 31, 2011 by sroux (800 points)
0 votes
1 answer

For creating a computer object, we want to check if the entered CN is already used in our AD. And for that we want to use a powershell script. An other dot ... powershell script should be start before creating the computer object, right? Thanks for your help.

asked Jun 4 by KEME (80 points)
0 votes
0 answers

Say you have Manager A that has 30 users under them. Manager A leaves and Manager B takes the position. What is the best way to update all 30 users so their new manager is Manager B.

asked Jun 7, 2021 by Jmbrown04 (60 points)
0 votes
1 answer

Just wanted to know if we could: Change the name of "Rename" Hide it altogether from the user page We've created a custom rename comand would prefer to simplify the user interface.

asked Nov 22 by msheppard (660 points)
3,589 questions
3,278 answers
8,303 comments
548,129 users