Simple do..while - check for user account existence.

Hello 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'
do {
$x = 0
$NewAlias = $FirstName[0], $LastName.Substring(0, $x), 'User' -join ""
$UserAlias = $NewAlias.ToLower()
write-output $UserAlias
$x = $x++
} while ([bool](Get-ADUser -Identity $UserAlias -ErrorAction SilentlyContinue) -eq $true)

Is it just a typo here in your post? … the variable you use in your Get-ADUser query is different to the variable inside your while loop. $UserAlias vs. $UserAlia

Thanks, edited :slight_smile: That was me fixing up variables for privacy reasons.