Link to home
Start Free TrialLog in
Avatar of mikedotm
mikedotm

asked on

Need a script that will identify users with first initial last name email address

Does anyone have, or know of a script or something that can search through AD and identify users that
have an email address of first initial last name @domain.com. I have tried csvde but the best I can do with that is export out proxy addresses which takes too much information. We are trying to phase out email addresses that are first initial last name and go with firstname.lastname for everyone. Many still have
the legacy first initial lastname email address.
Avatar of sirbounty
sirbounty
Flag of United States of America image

Perhaps something like this...

Dim objRoot:Set objRoot=GetObject("LDAP://RootDSE")
Dim objDomain:Set objDomain=GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))

EnumOUs(objDomain.ADsPath)

Sub EnumOUs(adspath)
  Dim objOUs, OU
  Set objOUs=GetObject(adspath)
  objOUs.Fileter=Array("OrganizationalUnit")
  Call EnumUsers(objOUs.ADsPath)
  For Each OU in objOUs
    Call EnumOUs(OU.ADsPath)
  Next
End Sub

Sub EnumUsers(adspath)
  Dim objUsers, User
  Set objUsers=GetObject(adspath)
  objUsers.Filter=Array("User")
  For Each User in objUsers
    strFI=Left(User.givenName,1)
    strLN=User.sn
    For Each addr in User.proxyAddresses
      If mid(addr,instr(addr,":")+1,instr(addr,"@")-instr(addr,":")-1)=strFI & strLN Then
         wscript.echo User.givenName & " " & User.sn & " has the email address that you're looking for!"
       End If
     Next
   Next
End Sub
Avatar of mikedotm
mikedotm

ASKER

This looks interesting. How would I run it? Do I need to specify a search base when I run it?
Name it as FindUsers.vbs and just double-click on it - it should work based upon your criteria...
Did you test this? I got a number of errors. Some I was able to fix but because I don't understand VB,
I was not able to continue.
Can you post the error(s) as well as the line # it occurred on.
I did test it, but I had to copy it by hand onto my home PC, from my work PC, so I sometimes mistype something...
This is what I get when I run it.


C:\>cscript findusers.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\findusers.vbs(23, 5) Microsoft VBScript runtime error: Object not a collection

C:\>

Thanks much!!
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Happy to help - thanx for the grade! :^)