0 votes

I need some help checking for unique usernames and changing them when they are found. I followed the tutorial and it looks like the script is working but as you can see the image below that the page is never submitted and can’t be. Any idea what or where I should be looking?

Jim

Import-Module Adaxes
function IsUserNameUnique($username)
{
$user = Get-AdmUser $username -erroraction silentlycontinue
return $user -eq $Null
}
# Get the username
$username = $Context.GetModifiedPropertyValue("samAccountName")
# Check if the username is unique
if (IsUserNameUnique($username))
{
return
}
# If the username is not unique, generate a unique one
$uniqueUsername = $Null
for ($i = 1; $True; $i++)
{
$uniqueUsername = $username + $i;
if (IsUserNameUnique($uniqueUsername))
{
break
}
}

# Update User Logon Name (pre-Windows 2000)
$Context.SetModifiedPropertyValue("samAccountName", $uniqueUsername)

# Update User Logon Name
$upnSuffix = $Context.GetObjectDomain("%distinguishedName%")
$userLogonName = $uniqueUsername + "@" + $upnSuffix
$Context.SetModifiedPropertyValue("userPrincipalName", $userLogonName)
$Context.LogMessage("The username has been changed to " + $userLogonName `
+ ".", "Information")

by (140 points)
0

Here is the image if it's not showing up in the first post.

http://news.polycomcsn.com/adaxes.png

1 Answer

0 votes
by (216k points)

Hello Jim,

The script is OK and works fine judging by the screenshot. The thing is in the user's Full Name property. A user's Full Name is also used as the Name property of the user account. Active Directory does not allow two objects that have identical RDNs be located in the same OU or container. The error message means that you have a user with the same RDN (that is, the same Full Name) in the same OU where you create the new user. If you create two users with the same Full Name in different OUs, Active Directory will allow you to do that as long as their usernames are different.

As an option, you can update the script for unique usernames and add code that also automatically changes the Full Name to make it unique within an OU. If you want, we can help you with such a script.

0

Thanks, help with a script would be great. Ideally I'd like a space and number added after the user's last name.

Thanks
Jim

0

Hello Jim,

An example of such a script can be found in the same tutorial where you've found the script for unique usernames. Take a look at Example 3 in the tutorial: http://www.adaxes.com/tutorials_Simplif ... Script.htm.

The script generates a unique username by adding a digit after the full name. To additionally add a space before a digit, find the following line in the script:

$objectName = $objectLeaf.Value + $i;

and replace it with the following line:

$objectName = $objectLeaf.Value + " " + $i

Related questions

0 votes
1 answer

We are in need of a script to check for unique employeeID prior to creating account and upon failure email the service desk with results. Please advise.

asked Nov 3, 2017 by willy-wally (3.2k points)
0 votes
1 answer

Hi. I'm hoping this will be an easy one but I've been looking all over the place for answer and can't seem to find it. How do you create a unique username ( ... get told that user already exists in domain. Thanks in advance for any pointers in the right place.

asked Apr 9, 2014 by AGMcCabe (50 points)
0 votes
1 answer

Is it possible to to get all users with a custom attribute defined? In PowerShell I'd be doing this: $s = get-aduser -filter 'Description -like "Sales Engineer"' | Select ... -like "True"' | Select Name Is this possible? Thanks for any help or tips!

asked Aug 7, 2018 by jake_h (300 points)
0 votes
0 answers

We have a process to create unique usernames but it doesn't account for hyphens. We would like to remove the hyphens and continue to use first initial plus the first seven characters from the ... ($UNLT - 1), $UN.Length)) $UNName + ([int]$UNNum + 1) } } }

asked Dec 11, 2015 by tcarp (20 points)
0 votes
1 answer

Dear Adaxes Support, I'm trying to check the uniqueness of the Initials-proberty. My script works well so far. Import-Module Adaxes $value = $Context.GetModifiedPropertyValue("initials"); if ( ... Have you a idea how I can do this in the right way? Thanks :-)

asked Aug 13, 2013 by Napoleon (700 points)
3,538 questions
3,229 answers
8,224 comments
547,747 users