We need an easy way to gather group and user information from our PDC in a format that will be easy to automate on our Linux box. [Check out nt2linux also. We like the flexibility of scripting our own stuff, but nt2linux might work for you.]
Here is a filter we whipped up in perl:
$grp=1; while(<>){ if(/\*/){ s/\n//; for($col=1;$col<=3;$col++){ @gr=split(/\*/,$_); @grpslist[$grp]=@gr[$col]; @grpslist[$grp]=~s/^\s*(.*?)\s*$/$1/; if(@grpslist[$grp]=~/\S/){ print @grpslist[$grp],"\n"; } $grp++; } } } |
Here are our groups:
C:s>net groups Group Accounts for CAESAR -------------------------------------------------------------------------- *Accounting *Accounting Memb RO *Accounting Members *Admin Memb RO *Admin Members *Contracts Memb RO *Contracts Members *Development Memb RO *Development Members *Domain Admins *Domain Guests *Domain Users *Exec Memb RO *Exec Members *IT Memb RO *IT Members *Marketing Memb RO *Marketing Members *Operations Memb RO *Operations Members *Public Memb RO *Public Members *Recruiting Memb RO *Recruiting Members *Sales Memb RO *Sales Members *Suits Memb RO *Suits Members The command completed successfully. C:s> |
This is what our filter spits out:
C:s>net groups | perl grplist.pl | more Accounting Accounting Memb RO Accounting Members Admin Memb RO Admin Members Contracts Memb RO Contracts Members Development Memb RO Development Members Domain Admins Domain Guests Domain Users Exec Memb RO Exec Members IT Memb RO IT Members Marketing Memb RO Marketing Members Operations Memb RO Operations Members Public Memb RO Public Members Recruiting Memb RO Recruiting Members Contracts Members Development Memb RO Development Members Domain Admins Domain Guests Domain Users Exec Memb RO Exec Members IT Memb RO IT Members Marketing Memb RO Marketing Members Operations Memb RO Operations Members Public Memb RO Public Members Recruiting Memb RO Recruiting Members Sales Memb RO Sales Members Suits Memb RO Suits Members C:s> |
For users, here is a filter that will spit out a list of users:
$usr=1; while(<>){ if($_=~/\S/ && $_!~/User accounts for / && $_!~/The command completed success/ && $_!~/---------------/){ s/\n//; @users=split; for($col=0;$col<=2;$col++){ print @users[$col]."\n"; $usr++; } } } |
Here are our users:
C:s>net users User accounts for CAESAR -------------------------------------------------------------------------- Administrator cdaines cimee Guest jbeam jsmith ljust okrust sperk The command completed successfully. C:s> |
Here is what the filter spits out:
C:s>net users | perl usrlist.pl | more Administrator cdaines cimee Guest jbeam jsmith ljust okrust sperk C:s> |
Oooooo…. but have we got a treat for you. You are going to need to get Dave Roth’s AdminMisc module. But once you have that you can combine the two scripts and add some code to provide a list of group membership on your servers. Here is the code:
use Win32::NetAdmin; system("net groups | perl grplist.pl > grplist.txt"); system("net users | perl usrlist.pl > usrlist.txt"); open (USR, "usrlist.txt") || die "File open error: $!\n"; foreach $usr (<USR>){ chomp $usr; open (GRP, "grplist.txt") || die "File open error: $!\n"; foreach $grp (<GRP>){ chomp $grp; if(Win32::NetAdmin::GroupIsMember('',$grp,$usr)){ print $usr." is a member of ".$grp."\n"; } } close GRP; } close USR; |
Here is the output:
Administrator is a member of Accounting Administrator is a member of Domain Admins Administrator is a member of Domain Users cdaines is a member of Admin Memb RO cdaines is a member of Contracts Memb RO cdaines is a member of Domain Users cdaines is a member of IT Memb RO cdaines is a member of Marketing Members cdaines is a member of Operations Memb RO cdaines is a member of Public Members cdaines is a member of Recruiting Members cdaines is a member of Sales Members cdaines is a member of Suits Memb RO cimee is a member of Admin Memb RO cimee is a member of Contracts Memb RO cimee is a member of Domain Users cimee is a member of IT Memb RO cimee is a member of Marketing Members cimee is a member of Operations Memb RO cimee is a member of Public Members cimee is a member of Recruiting Members cimee is a member of Sales Members cimee is a member of Suits Memb RO Guest is a member of Domain Guests jbeam is a member of Admin Members jbeam is a member of Contracts Memb RO jbeam is a member of Development Members jbeam is a member of Domain Users jbeam is a member of IT Members jbeam is a member of Marketing Members jbeam is a member of Operations Members jbeam is a member of Public Members jbeam is a member of Recruiting Members jbeam is a member of Sales Members jbeam is a member of Suits Memb RO jsmith is a member of Accounting jsmith is a member of Domain Users ljust is a member of Admin Members ljust is a member of Contracts Members ljust is a member of Development Members ljust is a member of Domain Users ljust is a member of Exec Members ljust is a member of IT Members ljust is a member of Marketing Members ljust is a member of Operations Members ljust is a member of Public Members ljust is a member of Recruiting Members ljust is a member of Sales Members ljust is a member of Suits Members okrust is a member of Admin Memb RO okrust is a member of Contracts Memb RO okrust is a member of Domain Users okrust is a member of IT Memb RO okrust is a member of Marketing Members okrust is a member of Operations Memb RO okrust is a member of Public Members okrust is a member of Recruiting Members okrust is a member of Sales Members okrust is a member of Suits Memb RO sperk is a member of Admin Members sperk is a member of Domain Users sperk is a member of IT Members sperk is a member of Marketing Members sperk is a member of Operations Memb RO sperk is a member of Public Members sperk is a member of Recruiting Members sperk is a member of Sales Members sperk is a member of Suits Memb RO |
Of course, you will need to modify the scripts above to suit your migration needs. You can use the same techniques to determine localgroup membership.