About LDAP:
LDAP stands for lightweight Directory Access Protocol. It is usually used to fetch (and sometimes update) data in a directory of people.
Using NET::LDAP module in Perl can provide a by interact with the this database.
Perl script to get this:
#! /usr/bin/perl
# Owner:rebecca
# Creation Date:2014-12-29
# Usage:
#./script.pl > YOURFILE.SCV
Use strict;
Use Win32;
Use Win32::ole;
Use NET::LDAP;
Use warnings;
Sub Getmembersingroup
{
(My $subldap, my $groupname) = @_;
#************************************get distinguished name by using group name************************************* ****
My $MESG = $subldap->search (
Base = "dc=global,dc=ds,dc=company,dc=com",
Filter = "(& (cn=. $groupname.")) ",
);
if ($MESG->code)
{
Print $MESG->error, "\ n";
Exit
}
My @entries = $MESG->entries;
My $distinguishedName;
foreach my $entry (@entries)
{
$distinguishedName = $entry->get_value ("distinguishedname");
}
#**********************get members by using the newly got distinguished name****************************************** ***
$MESG = $subldap->search (
Base = $distinguishedName,
Scope = "Sub",
Filter = "(& (objectclass=*))",
);
@entries = $MESG->entries;
My $entry;
foreach $entry (@entries)
{
My @member = $entry->get_value ("member");
foreach (@member)
{
my $line = $_;
my $para = $line;
My $string _dl = "Ou=distribution Lists";
$line =~/dc= (. *?),/;
My $str _domain = $;
if (!/$string _dl/)
{
#--------------Get the account name and domain name---------------------
my $str _obj = Win32::ole->getobject ("ldap://". $para) or Die "[email protected]";
My $status _able = "disabled";
if ($str _obj->{accountdisabled} eq 0)
{
$status _able = "Enabled";
}
$str _obj->{displayname} =~ s/\,//g; # Remove the, in the name
Print "$str _obj->{displayname}, $str _obj->{samaccountname}, $str _domain, $status _able \ n";
}
Else
{
#it is a DL need to get the members inside
$line = ~/cn= (. *?),/;
My $sub _group_name = $;
&getmembersingroup ($subldap, $sub _group_name);
}
}
}
}
My $ldap = net::ldap->new (' global.ds.company.com ') or die "[email protected]";
My $MESG = $ldap->bind (' [email protected] ', password = 'youraccountpassword');
if ($MESG->code)
{
Print $MESG->error, "\ n";
}
&getmembersingroup ($ldap, "GroupName");
How do I get all the members in user group by using LDAP in Perl?