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 (272k 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
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

I'm looking to setup a process where the HelpDesk or another IT user will basically go through a name change for a user and the modifications will kick off later at night. Basic ... to kick this off at 9pm at night. What's the best way to accomplish this?

asked Nov 13, 2023 by rurbaniak (1.4k points)
0 votes
1 answer

Is it possible to assign a custom display name for Microsoft Authenticator when a user scans their QR code? Right now when a user scans the QR code to register ... multiple account types and it would be hard to differentiate between the different OTP codes.

asked Aug 30, 2023 by curtisa (210 points)
3,346 questions
3,047 answers
7,782 comments
544,983 users