Hello Powershell.org Community,
First time poster, semi long term reader. Just need help with what I think will be straight forward for the professionals out there.
I'm trying to generate a username based on the first initials of their first and last name, and then adding 'user' on the end, ie 'SMUser'. However sometimes that username is taken, so I would like to take the second character of the last name, and add that to the user name ie 'SMcUser', this is easy enough to do, but I'm trying to take it further and ask it to check AD for an existing account, if it finds it, it extends the username even further by adding another character. I have never used do..while before, and I can see the problem, however I'm not sure if I'm going about it the right way.
Any help appreciated, oh and the silentlycontinue looks to be the main issue... it doesn't continue.
$FirstName = 'Steve'
$LastName = 'McQueen'
$x = 0
$NewAlias = $FirstName, $LastName.Substring(0, $x), 'User' -join ""
$UserAlias = $NewAlias.ToLower()
$x = $x++
} while ([bool](Get-ADUser -Identity $UserAlias -ErrorAction SilentlyContinue) -eq $true)