Skip to content

Instantly share code, notes, and snippets.

@nicholsonjf
Created August 1, 2013 23:31
Show Gist options
  • Save nicholsonjf/6136280 to your computer and use it in GitHub Desktop.
Save nicholsonjf/6136280 to your computer and use it in GitHub Desktop.
Perl script that prints the members of an Active Directory group in one column (as opposed to three columns like the command prompt NET command). Makes it easier to copy and paste the output.
# Provides warnings and error messages for debugging etc.
use strict;
# Importing the Win32::Netadmin module and one of its functions GroupGetMembers
use Win32::NetAdmin qw (GroupGetMembers);
# Syntax of GroupGetMembers function
# GroupGetMembers(server, groupName, userArrayRef)
# Fills userArrayRef with the members of groupName.
# Define variables to use as arguements in the GroupGetMembers function. Enter server name between quotes in $lookup_server
# Enter group name between quotes in $group_name
my $lookup_server = "";
my $group_name = '';
my @Domain_Group_User_List;
# Calling the Win32::NetAdmin::GroupGetMembers function with arguements
Win32::NetAdmin::GroupGetMembers($lookup_server, $group_name, \@Domain_Group_User_List);
# Loop that prints each value stored in the userArrayRef @Domain_Group_User_List
foreach my $domain_user(@Domain_Group_User_List)
{
print "$domain_user\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment