This blog is by design...

Thursday, September 01, 2005

Search your domain for a particular smtp email address, or 'proxyAddresses'

'********************************************
'script to search a domain for a particular SMTP address. searches
'users, groups and public folders. might not search against default
'users container, i don't use it and didn't test against it.
'Just modify the strAddress line to contain the address you're searching for
'thanks to EE's Chris-Dent for his OURecurse subroutine
'written by EE's kristinaw, 05/20/05

strAddress = lcase("SMTP:kris@norfolk.gov")
strFound = FALSE

Set objRootDSE = GetObject("LDAP://rootDSE")
Set objDomainRoot = GetObject("LDAP://"& _
objRootDSE.Get("defaultNamingContext"))

wscript.Echo "Searching for address "& strAddress

For Each objItem in objDomainRoot
If strFound = FALSE Then
'wscript.Echo objitem.Name
If objItem.Class="organizationalUnit" Then
'wscript.Echo objItem.ADSPath
OURecurse objItem.ADSPath
End If

If objItem.Class="user" Then
'wscript.Echo objItem.name
ProcessUsers objItem
End If

If objItem.Class="group" Then
ProcessUsers objItem
End If

'The below portion of code searches public folders
If objItem.cn ="Microsoft Exchange System Objects" then
'wscript.Echo objItem.Name
OURecurse objItem.ADSPath
End If
End If
Next

wscript.Echo "All Done"

Set objRootDSE = Nothing
Set objDomainRoot = Nothing


'**********************************************
Sub ProcessUsers(objUsers)
On Error Resume Next

'wscript.Echo objUsers.Name
set objProxy = GetObject("LDAP://"& objUsers.distinguishedName)
For Each proxyAddresses in objProxy.GetEx("proxyAddresses")
If lcase(proxyAddresses) = strAddress then
If objProxy.Class="publicFolder" then

wscript.Echo "Proxy address "& _
strAddress &" is assigned to a Public Folder named '"& _
objProxy.displayName &"', "&"in Public Folder Path "& _
objProxy.folderPathname

Else

wscript.Echo "Proxy address "& _
strAddress &" is assigned to the user or group "& _
"with a samAccountName of '"& objProxy.saMAccountName & _
"' and a display name of "& objProxy.displayName

End If
strFound = TRUE
End If
Next

set objProxy = Nothing

End Sub


'**********************************************
Sub OURecurse(objFirst)

' This OU is responsible for going through the AD Structure

Dim objOrgUnit, objItem

Set objOrgUnit = GetObject(objFirst)
For Each objItem in objOrgUnit
If objItem.Class="user" Then
'wscript.Echo objItem.Name
ProcessUsers objItem
End If

If objItem.Class="group" Then
ProcessUsers objItem
End If

If objItem.Class="publicFolder" Then
ProcessUsers objitem
End If

If objItem.Class="organizationalUnit" Then
'wscript.Echo objItem.Name
OURecurse objItem.ADSPath
End If
Next

Set objOrgUnit = Nothing
Set objFirst = Nothing

End Sub


'********************************************