0 votes

It is possible to automatically create the logon name based on eg %firstname% and %lastname%, however I want to achieve the following:

logon name = first letter FirstName, first letter of each MiddleName, LastName

e.g.:
Remco van der Test = RvdTest
Remco Test = RTest

I know the solution for the first character (%firstname%:lower,1) but my problem is the possible middle names. I could use an attribute like CustomAttributeText1 for each single MiddleName, however that makes it more difficult to explain to the users who can create an account where that field is used for.

How to achieve this?

With regards,

Remco

by (780 points)

1 Answer

0 votes
by (216k points)
selected by
Best answer

Hello,

In this case, you can use a script to generate the User Logon Name. For information on how to do this, follow this tutorial: http://adaxes.com/tutorials_Simplifying ... Script.htm. On the 5th step of the tutorial, paste the following script:

$firstName = $Context.GetModifiedPropertyValue("givenName")
$middleName = $Context.GetModifiedPropertyValue("middleName")
$lastName = $Context.GetModifiedPropertyValue("sn")

# Build samAccountName
$samAccountNameBuilder = New-Object "System.Text.StringBuilder"

# Append first character of the First Name
if (-not ([System.String]::IsNullOrEmpty($firstName)))
{
    $samAccountNameBuilder.Append($firstName.SubString(0,1).ToLower())
}

# Append first character of each of the Middle Names
if (-not ([System.String]::IsNullOrEmpty($middleName)))
{
    # Split Middle Name(s) into parts
    $middleNameParts = $middleName.Split(" ")
    $middleNamePartsCount = $middleNameParts.Count

    for ($i = 0; $i -lt $middleNamePartsCount; $i++)
    {
        $middleNamePart = $middleNameParts[$i]
        if ([System.String]::IsNullOrEmpty($middleNamePart))
        {
            continue
        }
        else
        {
            $samAccountNameBuilder.Append($middleNamePart.SubString(0,1).ToLower())
        }
    }
}

# Append Last Name
if (-not ([System.String]::IsNullOrEmpty($lastName)))
{
    $samAccountNameBuilder.Append($lastName.ToLower())
}

# Update samAccountName
$samAccountName = $samAccountNameBuilder.ToString()
$Context.SetModifiedPropertyValue("samAccountName", $samAccountName)

# Update userPrincipalName
$userPrincipalName = $samAccountName + "@" +
    $Context.GetObjectDomain("%distinguishedName%")
$Context.SetModifiedPropertyValue("userPrincipalName", $userPrincipalName)
0

very good support, is working perfect!! One of the reasons we're going to buy Adaxes...

With regards,

Remco Tiel

0

The script provided works well except for the following:

I adjusted the script with:
$fullName = "$firstName $middleName $lastName"
$Context.SetModifiedPropertyValue("cn", $fullName)

Instead of "cn" I also tried "fullName", however the account is not created. In the logging I see the following (translated):
there are more values added for a property that can only have one value...

Because Full Name is a required field I've set the field value to %firstName%, the script should change the name before creation. This works well for the field User Logon Name (pre-Windows 2000) which is also a required field. I've set this field also to %firstName% in the pattern file and is changed upon creation.

Is this by design or am I missing something?

With regards,

Remco Tiel

0

indeed I was missing something! Instead of using "cn" I had to use "name" to accomplish I wanted.

Remco

Related questions

0 votes
1 answer

I recently upgraded to version 2013.1 and since then a create user action on my help desk website no longer adds the @domainname.com to the User logon name field. ... there Exchange will not create the mailbox. Any help with this issue is appreciated. Thanks

asked May 13, 2013 by bemho (520 points)
0 votes
1 answer

Unfortunately, the logon names are not set automatically when a user is created. For the Full Name attribute everything is working fine. Where did I make a mistake here? Greetings, Robin

asked Apr 26, 2022 by robin.christmann (160 points)
0 votes
1 answer

Hello, A new question : when I create a new contact in Adaxes, I'd like the email address automatically created. How can I do this ? Thanks for your response. Yoann

asked Oct 15, 2012 by yoann.hamon (180 points)
0 votes
1 answer

Due to some of the systems we have, we must limit our logon names to 8 characters. When I set the Value Length to Maximum 8, the result when creating a new account ... get a popup "Invalid Value Length". Is there a way to autopopulate with only 8 characters?

asked Mar 18, 2013 by Kikaida (1.1k points)
0 votes
1 answer

I am attempting to block changing of SAM Account Name through a business rule. When attempting to do a rename in the portal, changing the SAM Account Name is offered at the same time, and despite not changing it the business rule is triggered. Thoughts?

asked Aug 21 by Daniel (160 points)
3,549 questions
3,240 answers
8,232 comments
547,814 users