#  DumpGroupMembership.pl
#  Example 6.7:
#  ----------------------------------------
#  From "Win32 Perl Scripting: Administrators Handbook" by Dave Roth
#  Published by New Riders Publishing.
#  ISBN # 1-57870-215-1
#
#  This script displays local and global groups a user is a member of.

use Win32;
use Win32::NetAdmin;
use Win32::Lanman;

$Name = Win32::LoginName() unless( $Name = shift @ARGV );
$Domain = Win32::DomainName();
Win32::NetAdmin::GetAnyDomainController( '', $Domain, $Dc );

Win32::Lanman::NetUserGetLocalGroups( $Dc, 
                                      $Name, 
                                      LG_INCLUDE_INDIRECT, 
                                      \@LocalGroups );
Win32::Lanman::NetUserGetGroups( $Dc, 
                                 $Name, 
                                 \@GlobalGroups );

foreach my $Hash ( sort( { $a->{name} cmp $b->{name} } 
                   ( @LocalGroups, @GlobalGroups ) ) )
{
    print "\t";
    print "$Hash->{name}\n";
}

