I would personally get away from using WinNT when you are working with
the AD. Here is some code I pulled together that will do what you want.
It isn't documented so ask away with questions.
use Win32::OLE;
$oRootDSE = Win32::OLE->GetObject("LDAP://RootDSE");
$varDomainNC = $oRootDSE->Get("defaultNamingContext");
$conContainer = $oRootDSE->Get("configurationNamingContext");
$oConnection = Win32::OLE->CreateObject("ADODB.Connection");
$oConnection->{Provider} = "ADSDSOObject";
$oConnection->Open();
$strQuery =
"<LDAP://$varDomainNC>;(objectClass=Group);adspath,groupType;subtree";
$oCommand = Win32::OLE->CreateObject("ADODB.Command");
$oCommand->{ActiveConnection} = $oConnection;
$oCommand->{CommandText} = $strQuery;
$oCommand->SetProperty('Properties','Page Size', "1000");
if(! ($objRS = $oCommand->Execute($strQuery)))
{
print "ADO->Execute error: " . Win32::OLE->LastError() . "\n";
exit 1;
}
if ($objRS->EOF)
{
print "Here\n";
}
while (! $objRS->EOF)
{
print ".";
if ($objRS->Fields('groupType')->value eq "-2147483646")
{
$objGroup =
Win32::OLE->GetObject($objRS->Fields('Adspath')->value);
@objGroup1 =
Win32::OLE::Enum->All($objGroup->{Members});
if (scalar @objGroup1 == "0")
{
$gnm{$objGroup->{samaccountname}}=$objGroup->{samaccountname};
}
else
{
$gwm{$objGroup->{samaccountname}}{Name}=$objGroup->{samaccountname};
foreach $oMember (@objGroup1)
{
$objUser =
Win32::OLE->GetObject($oMember->{adspath});
push
@{$gwm{$objGroup->{samaccountname}}{Member}}, $objUser->{displayname};
}
}
}
$objRS->MoveNext;
}
print "\n";
print "Global Groups with no Members\n";
foreach $group (sort keys %gnm)
{
print "$group\n";
}
print "\n";
print "Global Groups with Members\n";
foreach $group (sort keys %gwm)
{
print $gwm{$group}{Name} ."\n";
foreach $member (@{$gwm{$group}{Member}})
{
print "\t$member\n";
}
}
Kevin Ireland
Sr. Systems Engineer
Gentiva Health Services
(913) 814-2169
[EMAIL PROTECTED]
-----Original Message-----
From: Norris, Joseph [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 04, 2003 6:12 PM
To: Perl Admin (E-mail)
Subject: Another Active Directory question - this time users in groups
Group,
Here I am again asking for help on ActiveDirectory. I have the following
code:
sub ADS_check_name{
my ($user_name) = @_;
my %Config;
my $iCount = 0;
$Config{path} = "WinNT://" . Win32::DomainName();
if( $AD = GetADSIObject( \%Config ) ) {
my $Schema = Win32::OLE->GetObject( $AD->{Schema} );
foreach my $Object ( in $AD ) {
if ( $Object->{'Class'} eq 'Group' ) {
print "$Object->{Name}\n";
}
}
}
}
sub GetADSIObject {
my( $Config ) = @_;
my $ADSIObject;
my $ADsPath = $Config->{path};
$ADSIObject = Win32::OLE->GetObject( $ADsPath );
return( $ADSIObject );
}
I get a list of groups - which is what I want. However, now I need to
know which users are in which groups.
Any help would be most appreciated.
_______________________________________________
_______________________________________________
Perl-Win32-Admin mailing list [EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs