Solved

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

Posted on 2007-04-04
8
429 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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know all systems administrator at some time or another has had to create a script to copy file from a server share to a desktop. Well now there is an easy way to do this in Group Policy. Using Group policy preferences is not hard. The first thing …
Companies that have implemented Microsoft’s Active Directory need to ensure that the Active Directory is configured and operating properly. If there are issues found and not resolved, it eventually leads the components to fail or stop working and fi…
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

919 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

19 Experts available now in Live!

Get 1:1 Help Now