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.
Dim strDomainDN, strBase, strFilter, strAttrs, strScope
Dim objCmd, objConn, objRS
Dim proxyaddresses, proxyaddress
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
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
objDic.Add proxyAddress, objRS.Fields(1).value
wscript.echo "Total unique addresses found: " & objDic.Count
If iCount = 0 Then
Wscript.Echo "No dups found."
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, "|")
For each strName in arrNames
wscript.echo vbTab & strName