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 i have created a business role in that role if user is created a specific OU it will do everyting , generate password create email in specific DataBase , but i cannot find how to ... BA , according to this ou user should get @ba.com UPN , how can i do that?

asked Nov 29 by vagifazari (450 points)
0 votes
1 answer

Hi all, I have a condition during new user creation - Where the corporate email is entered into the email address field, but a custom drop-down for "Mailbox required?" is No. ... screen, and be able to save the result of this choice to a variable? Thanks all,

asked Oct 24 by dshortall (80 points)
0 votes
1 answer

I'm currently using CustomAttributeBoolean1 in order to differentiate end user and service accounts during user creation. I've added the attribute to the Property Pattern scoped for my ... a way to set the default value but have the field still be visible?

asked Jul 24 by awooten (80 points)
3,589 questions
3,278 answers
8,303 comments
548,155 users