Page 1 of 2 12>
Topic Options
#179635 - 2007-08-23 04:17 PM OT - Find SMTP Mail alias
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Does anybody know how to query for an smtp mail alias?
I want to find the user object that has a second smtp mail address.
I know the alias. How can I find the related user object?
It does not have to be KiX scripted. ;\)

Top
#179636 - 2007-08-23 04:39 PM Re: OT - Find SMTP Mail alias [Re: Witto]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
I think I am getting closer:
Error message: This e-mail address already exists in this organization

Top
#179637 - 2007-08-23 05:16 PM Re: OT - Find SMTP Mail alias [Re: Witto]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
It is about this error message, when trying to add a second smtp address to an existing mail user object.
Method one does not show me the answer.
Try to follow method 2, just downloaded Microsoft Network Monitor 3.1
But no luck so far...

Top
#179647 - 2007-08-24 08:56 AM Re: OT - Find SMTP Mail alias [Re: Witto]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Let me get this straight, you want to get the second SMTP alias from the User object of an Active Directory with Exchange installed, right ?
Top
#179648 - 2007-08-24 09:29 AM Re: OT - Find SMTP Mail alias [Re: Arend_]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Yep
I know the alias exists
I just don't know to what (user) object it is given
(At this moment, I am even unsure if it is a user object)

Top
#179649 - 2007-08-24 10:09 AM Re: OT - Find SMTP Mail alias [Re: Witto]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Here, spend 30+ mins figuring it out \:\)
 Code:
$strX400Search          = "X400:"
$strOutputFile = "D:\proxyaddresses.csv"

$objRootDSE = GetObject("LDAP://rootDSE")
$strDNSDomain = $objRootDSE.Get("defaultNamingContext")

;Set the ADO connection query strings
$QueryPath ="" + $strDNSDomain
$strFilter = "(&(proxyAddresses=*))"
$strAttributes = "adspath"

;Start the ADO connection
$objCommand = CreateObject("ADODB.Command")
$objConnection = CreateObject("ADODB.Connection")
$objConnection.Provider = "ADsDSOObject"
$objConnection.Open("Active Directory Provider")
$objCommand.ActiveConnection = $objConnection

;Create the Query
$strQuery = "<LDAP://" + $QueryPath + ">;" + $strFilter + ";" + $strAttributes + ";subtree"

$objCommand.CommandText = $strQuery
$objCommand.Properties("Page Size").value = 1000
$objCommand.Properties("Timeout").value = 30
$objCommand.Properties("Cache Results").value = 0

$objRecordSet = $objCommand.Execute

$objCount = 0
;objCount = $objRecordSet.RecordCount '<--not possible when 'caching results' is false
$addrCount = 0

$objRecordSet.MoveFirst

;Get the emailaddresses of all Items with a proxyaddress in the domain
While Not $objRecordset.EOF
  $objCount = $objCount + 1
  $strItemPath = $objRecordSet.Fields("AdsPath").Value
  $objItem = GetObject($strItemPath)
  $strObjClass = $objItem.class
  $ProxyAddresses = $objItem.proxyAddresses
  For Each $Proxy in $ProxyAddresses
    If Not InStr(UCase($Proxy), $strX400Search)
      $emailaddres = "present"
      $addrCount = $addrCount + 1
      $x = SubStr($proxy,1,4)
      Select
        CASE $x == UCASE("smtp")
          $emailaddres = SubStr($proxy,6) + ",Primary"
        CASE $x == LCASE("smtp")
          $emailaddres = SubStr($proxy,6) + ",Secondary"
      EndSelect
      $strResult = $strResult + @Crlf + $strObjClass + "," + chr(34) + $objItem.distinguishedName + chr(34) + "," + $emailaddres
    EndIf
  Next
  $objRecordSet.MoveNext
Loop

;Output to a text file
$objFileSystem = CreateObject("Scripting.FileSystemObject")
$objOutputFile = $objFileSystem.CreateTextFile($strOutputFile)
$objOutputFile.Write("objectClass,DistinguishedName,Emailaddress,pri/sec address,'")
$objOutputFile.Write($strResult)
$objOutputFile.close

? "Counted: " + $objCount + " records and " + $addrCount + " emailaddresses"

Top
#179653 - 2007-08-24 11:07 AM Re: OT - Find SMTP Mail alias [Re: Arend_]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
As you can see it's the ProxyAddresses property which is an Variant[] (array).
Top
#179654 - 2007-08-24 11:09 AM Re: OT - Find SMTP Mail alias [Re: Arend_]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Now that's cool.
took me five minutes to find that address.
I owe you something.
Thanks!

Top
#179655 - 2007-08-24 11:13 AM Re: OT - Find SMTP Mail alias [Re: Witto]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
No Problem \:\)
Top
#179659 - 2007-08-24 12:33 PM Re: OT - Find SMTP Mail alias [Re: Arend_]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Why not use the AD Users and Computers console?

Right click on domain, select search, click advanced tab, click "Fields" button and select "E-Mail address" and set the search criteria.

Not as much fun as scripting it, but it only took me 30 seconds to work out \:\/

Top
#179662 - 2007-08-24 01:16 PM Re: OT - Find SMTP Mail alias [Re: Richard H.]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
You are right Richard, but it only finds me the primary addresses, not the secondary.
Top
#179665 - 2007-08-24 01:30 PM Re: OT - Find SMTP Mail alias [Re: Witto]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
 Originally Posted By: Witto
You are right Richard, but it only finds me the primary addresses, not the secondary.


My Sentiments exactly.

Top
#179669 - 2007-08-24 01:47 PM Re: OT - Find SMTP Mail alias [Re: Arend_]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
 Originally Posted By: apronk
 Originally Posted By: Witto
You are right Richard, but it only finds me the primary addresses, not the secondary.


My Sentiments exactly.


Are you sure? Did you try?

I only ask because I tried this with my secondary address before I posted...

However I just tried with my primary address, and that doesn't work

Hmm....something odd going one here...give me a moment...

Top
#179671 - 2007-08-24 02:01 PM Re: OT - Find SMTP Mail alias [Re: Richard H.]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
You are quite right - I had my alternate address set as primary, so it wasn't searching on the secondary address array at all.

It just goes to show that coincindences happen more often than you'd think.

Top
#179673 - 2007-08-24 02:13 PM Re: OT - Find SMTP Mail alias [Re: Richard H.]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Besides, in my organization ppl have multiple email aliases and I want to know them all \:\)
Top
#179675 - 2007-08-24 02:32 PM Re: OT - Find SMTP Mail alias [Re: Arend_]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Simplified my previous script a WHOLE lot, basically rewrote it entirely \:\)
Upper Case SMTP = Primary
Lower Case smtp = Secondary
 Code:
$=SetOption('Explicit','On')
$=SetOption('NoVarsInStrings','On')
$=SetOption('NoMacrosInStrings','On')

Dim $adsDomain, $adsUser, $cnusr, $usrnfo, $usrmail
$adsDomain = GetObject("WinNT://"+@LDOMAIN)
$adsDomain.filter = "User",""
For Each $adsUser In $adsDomain
  ? $adsUser.Name
  $cnusr = TranslateName($adsUser.Name)
  $usrnfo = GetObject("LDAP://"+$cnusr)
  For Each $usrmail in $usrnfo.proxyAddresses
    ? $usrmail    
  Next
  ?
Next

Function TranslateName($NameToTranslate)
  Dim $NameTranslate
  $NameTranslate = CreateObject("NameTranslate")
  $NameTranslate.Init(3,"")
  $NameTranslate.Set(3, @LDOMAIN + "\" + $NameToTranslate)
  $TranslateName = $NameTranslate.Get(1)
EndFunction

Top
#179680 - 2007-08-24 03:55 PM Re: OT - Find SMTP Mail alias [Re: Arend_]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Great,
Saved your scripts and put your name on top
Thx

Top
#179682 - 2007-08-24 04:17 PM Re: OT - Find SMTP Mail alias [Re: Witto]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
No Problem, I love ADSI stuff \:\)
Top
#183613 - 2007-12-13 06:30 PM Re: OT - Find SMTP Mail alias [Re: Arend_]
werealldevo Offline
Fresh Scripter

Registered: 2007-10-03
Posts: 11
Hi,

I just wanted to add my version as an option.

 Code:
  
Break On
$FQDN = 'OU=users,DC=somedomain,DC=com'
$objADsPath = GetObject('LDAP://'+$FQDN)
For Each $obj in $objADsPath
    if $obj.Class = 'user'
        $usrDN = $obj.distinguishedName
        $usrFQDN= GetObject('LDAP://'+$usrDn)
        For Each $usrProxyAddr in $usrFQDN.proxyAddresses
            ? $usrProxyAddr
        Next
    endif
Next

Top
#183619 - 2007-12-13 07:58 PM Re: OT - Find SMTP Mail alias [Re: Witto]
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
You can allso query AD directly using ADODB
 Code:
CheckMailAdr("smtp:UserMail@@Domain.com")
  
Function CheckMailAdr($EMail)
	Dim $domCN,$Conn,$sLDAP

	If Not InStr($EMail,":")
		$EMail = "smtp:" + $EMail
	EndIf
	$domCN =  GetObject("LDAP://rootDSE").Get("defaultNamingContext")
	$Conn = CreateObject("ADODB.Connection")
	$Conn.Provider = "ADSDSOObject"
	$Conn.Open("ADs Provider")
	$sLDAP = "<LDAP://" + $domCN +  ">;(&(objectCategory=person)(proxyAddresses=" + $Email + "));adspath;subtree"
	$RecSet = $Conn.Execute($sLDAP)
	If $RecSet.RecordCount = 1
		$CheckMailAdr = $RecSet.Fields(0).Value
	Else
		$CheckMailAdr = ""
	EndIf
EndFunction

-Erik

Top
Page 1 of 2 12>


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 837 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.048 seconds in which 0.013 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org