0 votes

Hello,

I am looking for assistance in modifying our user creation script. When users with multiple names are being created for example, Jesus Geraldo Lopez, the user is being created as either L@123.com or jgeraldo l@123.com. Is there a way to modify our script to check for spaces in the first and last name field to and stop the user from being created? Also, would it be possible to modify the script to also check for special characters and replace them?

Here is our current user creation script. I appreciate any assitance. Thanks.

Import-Module Adaxes

function ReplaceCharacters($value)
{
    $map =@{ "å"="a"; "ö"="o"; "ä"="a";"ü"="u"; "ñ"="n"; "é"="e"; " "=""; "'"="" } # TODO: modify me

    foreach ($key in $map.Keys)
    {
        $value = $value.Replace($key, $map[$key])
    }

    return $value
}

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

# Get the username
$username = $Context.GetModifiedPropertyValue("samAccountName")
# Replace special characters in username
$username = ReplaceCharacters $username

# Check if the username is unique
$uniqueUsername = $Null
if (IsUserNameUnique($username))
{
    $uniqueUsername = $username
}

# If the username is not unique, generate a unique one
if ($uniqueUsername -eq $NULL)
{
    $firstName = $Context.GetModifiedPropertyValue("givenName")
    if ($firstName -ne $NULL)
    {
        # Add characters from first name, one by one
        $firstName = ReplaceCharacters $firstName
        for ($i = 0; $i -le $firstName.length; $i++)
        {
            $initial = $initial + $firstName[$i]
            $uniqueUsername = $username + $initial

            if (IsUserNameUnique($uniqueUsername))
            {
                break
            }

            $uniqueUsername = $Null
        }
    }
}

if ($uniqueUsername -eq $NULL)
{
    for ($i = 1; $True; $i++)
    {
        $uniqueUsername = $firstName + $username + $i
        if (IsUserNameUnique($uniqueUsername))
        {
            break
        }
    }
}

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

# Get domain name
$domaiName = $Context.GetObjectDomain("%distinguishedName%")

# Update User Logon Name
$Context.SetModifiedPropertyValue("userPrincipalName", "$uniqueUsername@$domaiName")
$Context.LogMessage("User Logon Name: $uniqueUsername@$domaiName", "Information")
by (520 points)

1 Answer

0 votes
by (480 points)
selected by
Best answer

You can also do this with a property pattern regex of: ^[a-zA-Z]+$

We created a First Name and Last Name pattern with that regex and it stops spaces from being entered in the web interface. Since you are using scripts to do this, i'm not sure how that would work, but you could give it a shot (or is there a way to use regex in powershell? I'm not a script guy so I really dont' know)

0

I think this method would work well, but would like to keep things limited to a script for now. Any update from support?

0

Looks like they have a script in their repository that will do what you want to do. You could take the pieces from that and use in your script:

http://www.adaxes.com/script-repository ... n-s299.htm

Related questions

0 votes
1 answer

Hi Support, We are looking to add a few things to one of the username creation scripts If the upn/username is not unique, add a character of the first name to the last name until ... ("The name has been changed to " + $objectName ` + ".", "Information") }

asked Apr 19, 2017 by vick04 (50 points)
0 votes
1 answer

This is a long shot but is there a way to script out the creation of Custom Commands? Right now when we create a new office (which is almost 2 times a months) we speend a ... is the 1st 3 letters so if the office is in Miami it MIA-Mangers and so on.

asked Jan 14, 2020 by hgletifer (1.3k points)
0 votes
1 answer

Hi team, I am facing currently an issue with new user/employee creation. I have this simple form And getting this error each time I already disabled all business rules and even property patterns - but still the same issue. What do I miss or oversee here ...?

asked Feb 19 by wintec01 (1.1k points)
0 votes
1 answer

Hi team, I am trying to limit the list of possible countries during user creation by this Property Pattern How ever during the creation the list is still full of other ... checked possibility to modify the form it self for Country - but no options available.

asked Jan 31 by wintec01 (1.1k points)
0 votes
0 answers

I used this script from the repository https://www.adaxes.com/script-repository/check-if-number-of-unused-microsoft-365-licenses-is-below-limit-s594.htm I have amended to include ... count is below what I specify. Please can you advise what I am doing wrong.

asked Jan 31 by MikeBeattie (90 points)
3,326 questions
3,026 answers
7,727 comments
544,678 users