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