Skip to content

Instantly share code, notes, and snippets.

@chrisbrownie
Created September 19, 2016 03:43
Show Gist options
  • Save chrisbrownie/9b3e559393edf6cf0168755ea1e3c412 to your computer and use it in GitHub Desktop.
Save chrisbrownie/9b3e559393edf6cf0168755ea1e3c412 to your computer and use it in GitHub Desktop.
Returns all SMTP proxy addresses for all users in a given domain or OU in CSV format
'======================================================================
' ListAllSMTPAddresses.vbs
'======================================================================
' Author: Chris Brown ([email protected])
' Date: 07/10/2014
' Details: Returns all SMTP proxy addresses for all users in a given
' domain or OU in CSV format
' Source: Unknown (I forget if I wrote this myself or found it somewhere)
'
'
'======================================================================
' Everything below this will be searched. Must be in the format
' of an LDAP DinguishedName
TopLevelDN = "DC=BlueYonderAirlines,DC=com"
' Do not modify below this line
'======================================================================
' Spit out the CSV headers
wscript.echo "TopLevelDN,sAMAccountName,SMTPAddress,IsPrimary"
' Get the top level OU's contents
Set OU = GetObject ("LDAP://" & TopLevelDN)
GetProxyAddressesInOU (OU)
Sub GetProxyAddressesInOU (OU)
' Iterate each object in the OU
For Each childObject in OU
' Check the object's type
Select Case childObject.class
Case "user"
' If it's a user ...
If Not childObject.mailnickname = "" Then
' User is mail enabled (mailnickname is NOT empty)
' Ignore errors at this bit
On Error Resume Next
For Each proxyAddress in childObject.proxyAddresses
If (Left(proxyAddress,5) = "SMTP:") Then
' It's an SMTP address
wscript.Echo TopLevelDN & "," & childObject.samaccountname & "," & Mid(proxyAddress,6) & ",True"
ElseIf (Left(proxyAddress,5) = "smtp:") Then
wscript.Echo TopLevelDN & "," & childObject.samaccountname & "," & Mid(proxyAddress,6) & ",False"
End If
Next
On Error GoTo 0
End If ' not mailnickname = ""
Case "organizationalUnit","container"
' If it's an OU or container, run this sub again
GetProxyAddressesInOU (childObject)
End Select ' childObject.class
Next
End Sub
'======================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment