• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 443
  • Last Modified:

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.
0
mikedotm
Asked:
mikedotm
  • 5
  • 3
1 Solution
 
sirbountyCommented:
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
0
 
mikedotmAuthor Commented:
This looks interesting. How would I run it? Do I need to specify a search base when I run it?
0
 
sirbountyCommented:
Name it as FindUsers.vbs and just double-click on it - it should work based upon your criteria...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
mikedotmAuthor Commented:
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.
0
 
sirbountyCommented:
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...
0
 
mikedotmAuthor Commented:
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!!
0
 
sirbountyCommented:
I don't have a way to test this just yet, but I know why you're getting the error...I 'think' (from memory) this should sort it - if not, post back and I can test at work...


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
    If IsArray(User.proxyAddresses) Then
      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
     End If
   Next
End Sub
0
 
sirbountyCommented:
Happy to help - thanx for the grade! :^)
0

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now