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?

link|improve this question

60% accept rate
do you have powershell available and the AD web service running? Not completely necessary but does make things easier. – tony roth Jan 5 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 at 16:59
feedback

1 Answer

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."
    }
}
link|improve this answer
Excellent ... thank you! – NYSystemsAnalyst Jan 5 at 17:45
feedback

Your Answer

 
or
required, but never shown

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