# mkGroup.pl (re)creates a group in the current NT domain. # Written 20-apr-1998 by fhb. # Usage: mkGroup groupname filename # where filename contains list of domain user account names. # # Adds users in groups of 3 to reduce number of system calls. # $bDebug = 0; $nTotal = 0; MAIN: $sAppName = "mkGroup"; $sVersion = "0.1"; print "$sAppName $sVersion\n"; unless ($#ARGV + 1) { die "Missing data file on command line.\n"; # somebody give me an arg! } $sGroup = $ARGV[0]; $sFile = $ARGV[1]; $sUsersToAdd = ""; # initialize empty string $n = 0; open(FDATA,$sFile) || die "Can't open file $sFile: $!\n"; print "Creating group $sGroup...\n"; $sCmd = sprintf("net group %s /add /dom >nul:",$sGroup); if ($bDebug) { print "debug> $sCmd\n"; } else { system($sCmd); } print "Adding users"; while () { if (!/^\!/) { # skip comments if ($n >= 3) { $sCmd = sprintf("net group %s %s /add /dom >nul:",$sGroup,$sUsersToAdd); if ($bDebug) { print "debug> $sCmd\n"; } else { system($sCmd); } $n = 0; $sUsersToAdd = ""; } chomp $_; s/\s//g; # remove whitespace $sUsersToAdd .= (" " . $_); # concat this user ++$n; ++$nTotal; print "."; } } close(FDATA); # If there's leftover users, add them: if ($n > 0) { $sCmd = sprintf("net group %s %s /add /dom >nul:",$sGroup,$sUsersToAdd); if ($bDebug) { print "debug> $sCmd\n"; } else { system($sCmd); } } print "\n$sAppName: created group $sGroup containing $nTotal users.\n";