We have a process to create unique usernames but it doesn't account for hyphens. We would like to remove the hyphens and continue to use first initial plus the first seven characters from the last name. In a hyphen situation, we just want to continue to use the last name entered in the first position.
Example:
John Jones-Smith would be jjones instead of jjones-s.
Here's the code we are currently using.
function incusername
{
$UNNum = 0
$UNNAme = ""
[int]$UNLT = $UN.ToString().Length
If ($UNLT -gt 8)
{
exit
}
$dummy = $UN -match '\D+'
$UNNAme = $matches[0].ToLower()
If ($UN -match '\d+')
{
$UNNum = $matches[0]
If ($UNNum -lt 9)
{
$UNName + ([int]$UNNum + 1)
}
Else
{
If ($UNNum -eq 9)
{
If ($UNLT -lt 8)
{
$UNName = $UN.Substring(0, [math]::Min(($UNLT - 1), $UN.Length))
$UNName + ([int]$UNNum + 1)
}
Elseif ($UNLT -lt 7)
{
$UNName + ([int]$UNNum + 1)
}
Else
{
$UNName = $UN.Substring(0, [math]::Min(($UNLT - 2), $UN.Length))
$UNName + ([int]$UNNum + 1)
}
}
Else
{
$UNName + ([int]$UNNum + 1)
}
}
}
Else
{
If ($UNLT -lt 8)
{
$UNName + ([int]$UNNum + 1)
}
Else
{
$UNName = $UN.Substring(0, [math]::Min(($UNLT - 1), $UN.Length))
$UNName + ([int]$UNNum + 1)
}
}
}