Tuesday, November 22, 2011

NET LOCALGROUP To Find Group Members from All Local Groups

For those like myself who are working with Windows 2000 servers, there aren't many choices when it comes to extracting local user and group information.  There is no DS commands and if you're only using a member server then there's no AD-related tools either.  As such, I manipulated the FOR and NET LOCALGROUP commands to create an output file which I can feed into a text cleaning program like PowerShell.  Use this command (from CMD.EXE) to create a file with all local groups and members thereof:

c:>FOR /F "delims=*" %X IN ('NET LOCALGROUP') DO NET LOCALGROUP %X >>GROUPLIST.TXT

The NET command in the parentheses produces a list of all local groups on the server.  The FOR command grabs each group, strips the * from the front of the group name output, and processes it as a variable in another NET LOCALGROUP command.  The result is added to a GROUPLIST.TXT file.  If you accidentally use one > then only one list, the last processed list, will be in your file.  The double > allows the file to receive additions without overwriting the existing data.

No comments: