Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

List of groups on Win32

by pwhysall (Acolyte)
on Feb 16, 2001 at 17:29 UTC ( #58854=perlquestion: print w/replies, xml ) Need Help??

pwhysall has asked for the wisdom of the Perl Monks concerning the following question:

I'm currently exploring Win32::NetAdmin, and have a seemingly simple requirement; list out the groups on a domain, and the users that belong to those groups. I can then do things to those users. (Evil BOFH cackle)

However, it appears that there is no simple function that returns a list of groups on the domain.

Is there a solution? Or do I have to start grabbing the output of external programs?

Replies are listed 'Best First'.
Re: List of groups on Win32
by clemburg (Curate) on Feb 16, 2001 at 17:35 UTC

    Get your copy of Win32 Perl Programming by Dave Roth. Pages 80-88 (Group Account Management) list want you want.

    Seems that you can retrieve a list of groups by using the Win32::AdminMisc::GetGroups() function.

    Christian Lemburg
    Brainbench MVP for Perl

      For anyone who's interested, I posted a review on Win32 Perl Scripting: Administrator's Handbook by Dave Roth and its here

      $code or die
      Using perl at
      The Spiders Web
      But I have a problem with AdminMisc - it seemed to install OK, but every time I call my little program:
      #!/usr/bin/perl -w
      use Win32::AdminMisc qw(GetDC GetGroups);
      my $dc;
      my @groups;
      $dc = GetDC();
      GetGroups($dc, GROUP_TYPE_ALL, \@groups);
      my $item;
      foreach $item(@groups) {
        print "$item\n";                                          

      I get an error message:

      bash-2.02$ perl
      "GetDC" is not exported by the Win32::AdminMisc module at line 3
      "GetGroups" is not exported by the Win32::AdminMisc module at line 3
      Can't continue after import errors at line 3
      BEGIN failed--compilation aborted at line 3.

      I'm not up on how perl modules and such work, so I don't know how to fix this :-(

        First off: baku's given you a good fix

        Here's the 'why' ... Perl modules that export symbols usually use the Exporter module internally. Such modules maintain lists of symbols (names of variables and subroutines) they automatically export (@EXPORT) and ones that they may export if asked to (@EXPORT_OK). (exported symbols can be accessed without fully qualifying their names).

        The module you're using doesn't list either of the symbols you're asking it to export (with the qw() construct) in its list of exportable symbols, hence the error.

        Philosophy can be made out of anything. Or less -- Jerry A. Fodor

        Try removing the qw[] block, and using the "qualified" names (like Win32::AdminMisc::GetGroups)... does that help any?

        I'm not up on how perl modules and such work,

        This can also be said for many authors of Win32:: modules. ): You'd think Dave Roth would know better by now, but perhaps it is just "history" for this particular module.

        A simple @EXPORT_OK= qw( list of subs ) would make this module easier to use (and fit the common expectations for a Perl module).

                - tye (but my friends call me "Tye")
        Those messages indicate that the module uses Exporter but did not put those functions in @EXPORT_OK to indicate that they could be exported. I would first check the module's documentation to see whether you have the names correct (including documentation) and if you do I would just stop trying to import them and use them directly, or I would add the lines:
        *GetDC = *Win32::AdminMisc::GetDC; *GetGroups = *Win32::AdminMisc::GetGroups;
        to manually import. (Well I would also go into the module, add a patch, and then send a bug report to the author, but that is just me...)
Re: List of groups on Win32
by rrwo (Friar) on Feb 17, 2001 at 22:49 UTC

    I think Win32::Lanman (see might be more appropriate.

    You probably want to check out <cite>Win32 Perl Scripting: The Administrator's Handbook</cite> by Dave Roth (see the author's home page at It's got a lot of useful information and using Perl for various sysadmin tasks.

That's one small step for a pwhysall...
by pwhysall (Acolyte) on Feb 20, 2001 at 19:42 UTC
    The first task was to print a comma separated list of users and groups:
    #!/usr/bin/perl -w use Win32::AdminMisc; use Win32::NetAdmin qw (GroupGetMembers); use strict; my $dc; my @groups; $dc = Win32::AdminMisc::GetDC(); Win32::AdminMisc::GetGroups($dc, GROUP_TYPE_ALL, \@groups); my $item; my %groups_with_users; foreach $item(@groups) { my @tmp_user_list; GroupGetMembers($dc, $item, \@tmp_user_list); $groups_with_users{$item} = [@tmp_user_list]; } my $group; open USERGROUP, ">usergroup.csv" || die "Can't open file for writing:$ +!"; print USERGROUP "Group, User\n"; foreach $item(keys %groups_with_users) { my $i; foreach $i (0 .. $#{ $groups_with_users{$item} } ) { print USERGROUP "$item, $groups_with_users{$item}[$i]\n"; } } close USERGROUP;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://58854]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2020-10-25 00:23 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (248 votes). Check out past polls.