Solved

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

Posted on 2007-04-04
8
428 Views
Last Modified: 2010-03-17
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
Comment
Question by:mikedotm
  • 5
  • 3
8 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18852351
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
 

Author Comment

by:mikedotm
ID: 18858138
This looks interesting. How would I run it? Do I need to specify a search base when I run it?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18860891
Name it as FindUsers.vbs and just double-click on it - it should work based upon your criteria...
0
 

Author Comment

by:mikedotm
ID: 18905027
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 67

Expert Comment

by:sirbounty
ID: 18905188
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
 

Author Comment

by:mikedotm
ID: 18918566
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
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18950719
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 18966608
Happy to help - thanx for the grade! :^)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

There are two modes of restricted groups GPOs. Replacing mode:   Additive mode:   How do they work? Replacing mode: Everything (users, groups, computers) that is member of the local administrators group will be cleared out. After th…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now