Checking ProxyAddresses for Duplicates

Originally published December 30, 2004

 

Today I needed to know if all of my proxyaddresses (that is, the entries on the “E-Mail Addresses” tab in Active Directory Users and Computers) were unique.

ADU&C prevents you from entering a duplicate manually, but it's possible for a script or for the RUS to generate a duplicate under certain situations.

So, I wrote a script. There are several ways to attack this problem,  including using adfind and adcsv (which Joe Richards has done) but I wanted a vbscript solution.

My solution is below. It can easily be modified to dump all of your addresses as well.

Option Explicit

Dim strDomainDN, strBase, strFilter, strAttrs, strScope
Dim objDIC
Dim objCmd, objConn, objRS
Dim proxyaddresses, proxyaddress
Dim iCount

strDomainDN = "dc=brnets,dc=int"
strBase   =  "<GC://" & strDomainDN & ">;"

strFilter = "(proxyAddresses=*);"
strAttrs  = "name,adspath,proxyaddresses;"
strScope  = "subtree"

Set objDIC = CreateObject ("Scripting.Dictionary")

Set objConn = CreateObject ("ADODB.Connection")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"

Set objCmd = CreateObject ("ADODB.Command")

objCmd.ActiveConnection = objConn
objCmd.CommandText = strBase & strFilter & strAttrs & strScope
objCmd.Properties ("Page Size") = 1000

Set objRS = objCmd.Execute
objRS.MoveFirst

while Not objRS.EOF
 'Wscript.Echo "name = " & objRS.Fields(0).Value
 'wscript.echo "adspath = " & objRS.Fields(1).Value
 proxyaddresses = objRS.Fields(2)
 for each proxyaddress in proxyaddresses
  proxyaddress = LCase (proxyaddress)
  If objDic.Exists (proxyaddress) Then
   objDic.Item (proxyAddress) = objDic.Item (proxyAddress) & "|" & objRS.Fields(1).Value
   wscript.echo "Dup: " & objDic.Item (proxyAddress)
   iCount = iCount + 1
  Else
   objDic.Add proxyAddress, objRS.Fields(1).value
  End If
 next
 'wscript.echo
 objRS.MoveNext
wend

wscript.echo "Total unique addresses found: " & objDic.Count

If iCount = 0 Then
 Wscript.Echo "No dups found."
Else
 Dim objArr, objIt, strVals

 wscript.echo iCount & " dups found."
 objArr = objDic.Keys
 For Each objIt in objArr
  strVals = objDic.Item (objIt)
  If Instr (strVals, "|") > 0 Then
   Dim arrNames, strName

   arrNames = Split (strVals, "|")
   wscript.echo objIt
   For each strName in arrNames
    wscript.echo vbTab & strName
   Next
  End If
 Next
End If

wscript.quit 0

Published Tuesday, November 13, 2007 7:26 PM by michael

Comments

No Comments