I found myself a solution based on the examples from the book suggested by strat.
Here is an example of minimal code for a function that returns the type of group (including universal groups) for a given group, in case anybody is interested.
#!perl
use warnings;
use strict;
use Win32::OLE;
# map group type codes to meaningful names
my %groupType = (
-2147483644 => 'Local Security Group',
-2147483646 => 'Global Security Group',
-2147483640 => 'Universal Security Group',
4 => 'Local Distribution Group',
2 => 'Global Distribution Group',
8 => 'Universal Distribution Group',
-2147483643 => 'Builtin Group'
);
my $groupname = 'DOMAIN\GROUP';
print $groupname, " => ", GroupType($groupname);
sub GroupType
{
my($domain,$group) = split /\\/,shift;
# Set up the ADO connections
my $connObj = Win32::OLE->new('ADODB.Connection');
$connObj->{Provider} = "ADsDSOObject";
$connObj->Open;
my $commObj = Win32::OLE->new('ADODB.Command');
$commObj->{ActiveConnection} = $connObj;
# Grab the default root domain name
my $rootDSE = Win32::OLE->GetObject("LDAP://$domain/RootDSE");
my $rootNC = $rootDSE->Get("defaultNamingContext");
# Run ADO query and return the group type
my $query = "<LDAP://$domain/$rootNC>;";
$query .= "(&(CN=$group)(objectClass=Group));";
$query .= "cn,groupType;";
$query .= "subtree";
$commObj->{CommandText} = $query;
my $resObj = $commObj->Execute($query);
die "Could not query $domain: ",$Win32::OLE::LastError,"\n" unless
+ ref $resObj;
return($groupType{$resObj->Fields("groupType")->value});
}
Max |