Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: How to enumerate universal groups in Windows

by MaxKlokan (Monk)
on Apr 26, 2007 at 12:52 UTC ( #612184=note: print w/replies, xml ) Need Help??


in reply to How to enumerate universal groups in Windows

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://612184]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2020-10-23 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (234 votes). Check out past polls.

    Notices?