To change the previous perl script to give the same output it would look something like
open ofh,">QueryOutput.csv" or die("ERROR: Can't open CSV output file: $!\n"); print ofh "First Name, Last Name, ID, Primary Mail Address,,Additional Email Addresses....\n"; @out=`adfind -nodn -sc exchaddresses:smtp -csv -csvq \"\" -csvmvdelim , -nocsvheader givenname sn samaccountname mail`; foreach $thisline (@out) { $thisline=~s/smtp://ig; # strip smtp: and SMTP: print ofh $thisline; } :) Then to take it a step further for the later conversation about a disjoint between mail and proxyaddresses primary SMTP (yes this is possible I see it pretty regulary in companies, it is only enforced I believe by ADUC, nothing in Exchange) you can make the script identify cases where you have a disjoint between mail and the primary SMTP with something like open ofh,">QueryOutput.csv" or die("ERROR: Can't open CSV output file: $!\n"); print ofh "Disjoint Mail Attribs, First Name, Last Name, ID, Primary Mail Address,,Additional Email Addresses....\n"; @out=`adfind -nodn -sc exchaddresses:smtp -csv -csvq \"\" -csvmvdelim , -nocsvheader givenname sn samaccountname mail`; foreach $thisline (@out) { ($mail,$primarysmtp)=($thisline=~/,([^,[EMAIL PROTECTED],]+),.*SMTP:([^,[EMAIL PROTECTED],]+)[\n,]/) ; $disjoint=($mail ne $primarysmtp)?"TRUE":"FALSE"; $thisline=~s/smtp://ig; # strip smtp: and SMTP: print ofh "$disjoint,$thisline"; } joe -- O'Reilly Active Directory Third Edition - http://www.joeware.net/win/ad3e.htm -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Fuller, Stuart Sent: Friday, January 26, 2007 1:46 PM To: ActiveDir@mail.activedir.org Subject: RE: [ActiveDir] How to find non-primary SMTP addresses? Here is a cheesy VB script to list email addresses and kick them to a CSV file***. It's not horribly efficient, tight coding, or cleaned up very much but it has worked for me. Remember to replace the <LDAP Path> with yours and you may have to adjust the page size if you have more than 2000 objects. Also watch for line feeds in the code that may be email caused. Have fun.. _Stuart Fuller (***Full disclaimer of liability - use at own risk) ------------------------------------------------------- '---------------------- 'ListUsers Email Script 'Stuart Fuller '7/7/05 '---------------------- Dim adsComputer Dim adsOU Dim operatingSystem Dim osVersion Dim servicePack Dim fileSys Dim fileTxt Const ForReading = 1, ForWriting = 2, ForAppending = 8 wscript.echo "Start" 'Create the output file set fileSys = CreateObject("Scripting.FileSystemObject") Set fileTxt = fileSys.OpenTextFile("QueryOutput.csv", ForWriting, True) fileTxt.Writeline("First Name, Last Name, ID, Primary Mail Address,,Additional Email Addresses....") 'Create the connection to AD Const ADS_SCOPE_SUBTREE = 2 Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCOmmand.ActiveConnection = objConnection 'Set the SQL type query against AD '****REPLACE <LDAP PATH> with OU or domain you want to query in the objCommand.Commandtext line '****Example 'LDAP://ou=users,dc=joeware,dc=com' objCommand.CommandText = "Select givenName, sn, sAMaccountName, mail, ADsPath from '<LDAP PATH>'" _ & "where objectClass='user' AND objectCategory='Person'" objCommand.Properties("Page Size") = 2000 objCommand.Properties("Timeout") = 60 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.Properties("Cache Results") = False Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst 'Loop through the returned records Do Until objRecordSet.EOF strGName = objRecordSet.Fields("givenName").value strSName = objRecordSet.Fields("sn").value strMail = objRecordSet.Fields("mail").value strSAM = objRecordSet.Fields("sAMaccountName").value 'In order to get the multi-varied attribute go get the user object 'and then query the proxyaddress attribute set objUser = GetObject(objRecordSet.Fields("ADsPath").value) on error resume next For each strProxyAddress in objUser.ProxyAddresses strAdd = Left(strProxyAddress,4) If ((strAdd = "SMTP") OR (strAdd = "smtp")) Then strAddress = Right(strProxyAddress, LEN(strProxyAddress) - 5) strAddAll = strAddAll & strAddress & "," End If Next fileTxt.WriteLine(strGName & "," & strSName & "," & strSAM & "," & strMail & ", ," & strAddAll ) 'Since we are using strAddAll as additive - clear the vars strAddress = null strAddAll = null 'Go grab the next record and restart loop objRecordSet.MoveNext Loop wscript.echo "DONE" -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of joe Sent: Thursday, January 25, 2007 11:31 PM To: ActiveDir@mail.activedir.org Subject: RE: [ActiveDir] How to find non-primary SMTP addresses? Yeah JoeK is right on, nothing in LDAP will help you with this. The proxyAddresses attribute is case insensitive so there is no way to query to just get addresses that are secondary. AdFind can help with this in a small perl script. You use the CSV capability of AdFind combined with its ability to only display the multivalue attributes that have a string match to smtp (AdFind isn't case sensitive either for this query). That simply outputs just smtp addresses so it is nice and clean. The perl script would look something like @out=`adfind -sc exchaddresses:smtp -csv -nocsvheader`; foreach $thisline (@out) { next unless $thisline=~/smtp:.+/; $thisline=~s/(SMTP:.+)([\";])/$2/; # strip out primary $thisline=~s/;{2,}/;/; # cleanup multiple semicolons $thisline=~s/;\"/\"/; # cleanup semicolon/quote print $thisline; } -- O'Reilly Active Directory Third Edition - http://www.joeware.net/win/ad3e.htm -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Joe Kaplan Sent: Thursday, January 25, 2007 7:52 PM To: ActiveDir@mail.activedir.org Subject: Re: [ActiveDir] How to find non-primary SMTP addresses? In addition to what Ulf said, there also isn't any practical way to query for users that have secondary addresses vs. only having a primary and there isn't any practical way to just get the secondary addresses out of the proxyAddresses attribute. You essentially need to get all the data and then check for the values that are prefixed with lower case "smtp". Maybe Joe R. has a neat trick with ADFind to make this easier, but LDAP itself doesn't help much. Joe K. ----- Original Message ----- From: Ulf B. Simon-Weidner To: ActiveDir@mail.activedir.org Sent: Thursday, January 25, 2007 6:00 PM Subject: RE: [ActiveDir] How to find non-primary SMTP addresses? Hi Stu, I don't think there's a way to expose mulitvalued attributes with CSVDE - you'd either have to use LDIFDE or VBScript or anything else to view all values of those attributes. Gruesse - Sincerely, Ulf B. Simon-Weidner Profile & Publications: http://mvp.support.microsoft.com/profile=35E388DE-4885-4308-B489-F2F1214 C811 D Weblog: http://msmvps.org/UlfBSimonWeidner Website: http://www.windowsserverfaq.org From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Stu Packett Sent: Freitag, 26. Januar 2007 00:53 To: ActiveDir@mail.activedir.org Subject: [ActiveDir] How to find non-primary SMTP addresses? How does one go about getting the non-primary SMTP addresses for every Exchange user? I can't seem to find a way via csvde, but maybe I'm doing something wrong. Thanks again. List info : http://www.activedir.org/List.aspx List FAQ : http://www.activedir.org/ListFAQ.aspx List archive: http://www.activedir.org/ma/default.aspx List info : http://www.activedir.org/List.aspx List FAQ : http://www.activedir.org/ListFAQ.aspx List archive: http://www.activedir.org/ma/default.aspx List info : http://www.activedir.org/List.aspx List FAQ : http://www.activedir.org/ListFAQ.aspx List archive: http://www.activedir.org/ma/default.aspx List info : http://www.activedir.org/List.aspx List FAQ : http://www.activedir.org/ListFAQ.aspx List archive: http://www.activedir.org/ma/default.aspx