rc has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to use ldapsearch to query AD and parse the results using perl. I'm having trouble with the multivalue attributes like proxyAddresses; I'm only getting the first value returned.
##### Edit these variables ##### my $delim = "*!*"; my $attributes = "cn displayName employeeID extensionAttribute3 extensionAttribute1 mail mailNickname proxyAddress +es userPrincipalName"; my $server = "server1"; my $basedn = "dc=mycorp,dc=com"; ################################ ...snip... $/ = ''; #Paragraph mode for input my @atts = split(/ /, $attributes); my $cmd = "ldapsearch $flags -h $server -b \"$basedn\" \"(mail=*)\" $a +ttributes"; open(SEARCH, "$cmd |") or die "\nError: $!\n"; while(<SEARCH>) { my $line; foreach my $att (@atts) { $line .= lc(/^$att: *(.*)$/im ? $1 : '') . $delim; } } This is the data that ldapsearch returns: dn: CN=Connors\, Ralph,OU=Users,DC=mycorp,DC=com cn: Connors, Ralph displayName: Connors, Ralph mail: rconnors@mycorp.com employeeID: 1234567 proxyAddresses: MBX:1 proxyAddresses: smtp:rconnors@mailgw proxyAddresses: SMTP:rconnors@mycorp.com proxyAddresses: X400:c=US;a= ;p=mycorp;o=NA;s=Chastain;g=Robert; proxyAddresses: RFAX:Connors, Ralph@ userPrincipalName: rconnors@mycorp.com extensionAttribute1: 0012A extensionAttribute3: 1234567 mailNickname: rconnors
I forgot to mention I'm setting $/ = ''; for paragraph mode.
This works fine for all but the multivalue attributes.
What am I missing wise ones?
Thanks, RC
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: parsing ldapsearch results
by sgifford (Prior) on May 03, 2004 at 16:50 UTC | |
|
Re: parsing ldapsearch results
by NetWallah (Canon) on May 03, 2004 at 18:50 UTC |