Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to search my Active Directory for all users that DO NOT match the following criteria:

First letter of login name matches first letter of first name. Remainder of login name matches last name.

So, user John Smith with logon jsmith would be a match. How can I query AD to find users who do not match this criteria?

share|improve this question
do you have powershell available and the AD web service running? Not completely necessary but does make things easier. – tony roth Jan 5 '12 at 16:49
Powershell - yes. I'm not sure about the AD web service. I need to talk to the admin. Even with powershell, what would the query look like? – NYSystemsAnalyst Jan 5 '12 at 16:59
up vote 2 down vote accepted

Here is a little PowerShell script that uses the Quest AD cmdlets, available here. It constructs the desired logon and then compares it to the current logon, writing out the invalid logon names to the console window. You could have it output to a file or whatever.

$users = Get-QADUSer -SizeLimit 0

foreach ($user in $users)

$firstinitial = $user.FirstName.Substring(0,1)
$lastname = $user.LastName.ToString()
$compareterm = $firstinitial + $lastname
if ($compareterm -ne $user.LogonName)
    Write-Host $compareterm "has an invalid logon name."
share|improve this answer
Excellent ... thank you! – NYSystemsAnalyst Jan 5 '12 at 17:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.