0 votes

Example: If a user has a ' in theirname: Fred J O'neal. Normally the username is set as %lastname:lower,4%%firstname:lower,3%%initials:lower% Problem is o'nefrej would be the result. I'm not sure if i can target specific characters to ignore the '. I would like to set it to oneafrej to be the result. if (($FN.substring(1,1) -eq '-') -or ($FN.Substring(1,1) -eq "'")) { $Context.LogMessage("%firstname% %initials% %lastname% has a hyphen or single quote at the second character in the first name", "Information") $username = #this is what I'm not sure how to do?

by (1.0k points)
0

Hello,

For us to help you with a solution, please, specify what should be done in case such characters are present in the first name and/or last name. Should such characters just be ignored when forming usernames?

0

So in the example I gave you The user is built by using first four of last name first 3 of first name and the initial which will be one character. The name is Fred J O'neal. Instead of o'nefrej I want the 1 character of the last name, skip the second character which is the ' use the next 3 after the ' so it would end up with oneafrej. Whith this one example I can script out the other use cases. so instead of $username = %lastname:lower,4%%firstname:lower,3%%initials:lower% It should be $username = ????? The only two characters that are allowed are - for hyphenated names or ' for names like O'neal etc.

1 Answer

+1 vote
by (294k points)

Hello,

To achieve the desired, you need to first remove the unwanted characters from the values and then extract the required number of characters. Here is a script on how to do that:

$unwantedCharacters = @("'", " ") # TODO: modify me

function ReplaceCharacters ($value, $characters)
{
    foreach ($character in $characters)
    {
        $value = $value.Replace($character, "")
    }
    return, $value
}

$firstName = ReplaceCharacters "%firstname:lower%" $unwantedCharacters
$lastName = ReplaceCharacters "%lastname:lower%" $unwantedCharacters
$initials = ReplaceCharacters "%initials:lower%" $unwantedCharacters

$username = $firstName.SubString(0, 4) + $lastName.SubString(0, 3) + $initials
0

I actually resolved this a different way. I created a variable that picks up the caracters after the special. $Context.LogMessage("%firstname% %initials% %lastname% has a hyphen or single quote at the second character in the last name", "Information")

#Variable to set up skipping the - or '
$NFN = $LN.Substring(2,3).ToLower() 
$username = "%lastname:lower,1%"+$NFN+"%firstname:lower,3%%initials:lower%"
0

Hello,

First of all, it will not work if there is an unwanted character in the first name or initials. Also, it will work only if the unwanted character is second in the last name. The approach we suggested is more flexible, but if your script meets your needs, it should work fine.

Related questions

0 votes
1 answer

Hi there, I've created a Delete User feature in the Web Interface Configurator. I am trying to restrict object selection via a User Criteria. Need to exclude Service ... won't appear when selecting target user for the 'Delete User' feature. Thanks, David

asked Sep 19 by dshortall (80 points)
0 votes
0 answers

We are in hybrid mode with 365. All the accounts we create have to made with a .com instead of .local. How can I make that change in adaxes? Or is this some default I need to change in AD instead?

asked Apr 11, 2022 by LEGIT1 (150 points)
0 votes
1 answer

Thanks for the info. I'm now grabbing the %adm-ManagerUserName% value, but need to remove the final 21 characters of it so it contains only their username and not our ... this in the PowerShell Script Editor for my business rule, I get the following error:

asked Mar 11, 2021 by mkvidera (60 points)
0 votes
1 answer

How I can ignore a part of the lastname in username composition? Example: In the fullname "John da Silva", "da Silva", is the lastname, so, I need ignore the "da " in the composition of username, when I create the new user.

asked May 22 by fgmello (40 points)
0 votes
1 answer

Using this built in function: There is no option to change the domain on the user account, however this is not the domain we use for UPN. However after creating a user, you can change it but trying to avoid going back into the object.

asked Apr 14, 2023 by mightycabal (1.0k points)
3,588 questions
3,277 answers
8,303 comments
548,079 users