Parsing local groups?

L

LWG

I have a server that has 100 local groups configured. What I need to do is
parse the list to a file then push them back into another server. Is that
possible?

The output looks something like: (using net localgroup)

*OWS_1382446396_Administra*OWS_1382446396_advauthor *OWS_157286859_admin
*OWS_157286859_Administrat*OWS_157286859_author *OWS_157286859_browser
*OWS_157286859_Browser (Mi*OWS_157286859_collab *OWS_157286859_Project
Man
*OWS_157286859_Team Member*OWS_157286860_admin
*OWS_157286860_Administrat
*OWS_157286860_Browser (Mi*OWS_157286860_Project Man*OWS_157286861_admin
*OWS_157286861_Administrat*OWS_157286861_Browser (Mi*OWS_157286861_Project
Man
*OWS_157286861_Team Member*OWS_157286863_admin
*OWS_157286863_Administrat
*OWS_157286863_Browser (Mi*OWS_157286863_Project Man*OWS_157286863_Team
Member
*OWS_157286865_admin *OWS_157286865_Administrat*OWS_157286865_Browser
(Mi
*OWS_157286865_Project Man*OWS_157286958_admin
*OWS_157286958_Administrat
*OWS_157286958_Browser (Mi*OWS_157286958_Project Man*OWS_157286958_Team
Member
*OWS_157286960_admin *OWS_157286960_Administrat*OWS_157286960_Browser
(Mi
*OWS_157286960_Project Man*OWS_157286960_Team Member*OWS_157286963_admin
*OWS_157286963_Administrat*OWS_157286963_Browser (Mi*OWS_157286963_Project
Man
*OWS_157286963_Team Member*OWS_157286964_admin
*OWS_157286964_Administrat
*OWS_157286964_Browser (Mi*OWS_157286964_Project Man*OWS_157286966_admin
*OWS_157286966_Administrat*OWS_157286966_Browser (Mi*OWS_157286966_Project
Man
*OWS_157286966_Team Member*OWS_157286967_admin
*OWS_157286967_Administrat
*OWS_157286967_Browser (Mi*OWS_157286967_Project Man*OWS_157286967_Team
Member
*OWS_157287059_admin *OWS_157287059_Administrat*OWS_157287059_Browser
(Mi
*OWS_157287059_Project Man*OWS_157287065_admin
*OWS_157287065_Administrat
*OWS_157287065_Browser (Mi*OWS_157287065_Project Man*OWS_157287065_Team
Member
*OWS_157287067_admin *OWS_157287067_Administrat*OWS_157287067_Browser
(Mi
*OWS_157287067_Project Man*OWS_157287068_admin
*OWS_157287068_Administrat
*OWS_157287068_Browser (Mi*OWS_157287068_Project Man*OWS_157287068_Team
Member
*OWS_157287161_admin *OWS_157287161_Administrat*OWS_157287161_Browser
(Mi
*OWS_157287161_Project Man*OWS_157287161_Team Member*OWS_157287163_admin

The groups should look like

OWS_1382446396_admins
server 8081 admins....

Thx
 
J

Jerold Schulman

ADDUSERS from the reskit supplement will dump groups (and membership) and import
them to another server. See the list of tools and pricing at tip 3277 in the
'Tips & Tricks' at http://www.jsiinc.com

I have a server that has 100 local groups configured. What I need to do is
parse the list to a file then push them back into another server. Is that
possible?

The output looks something like: (using net localgroup)

*OWS_1382446396_Administra*OWS_1382446396_advauthor *OWS_157286859_admin
*OWS_157286859_Administrat*OWS_157286859_author *OWS_157286859_browser
*OWS_157286859_Browser (Mi*OWS_157286859_collab *OWS_157286859_Project
Man
*OWS_157286859_Team Member*OWS_157286860_admin
*OWS_157286860_Administrat
*OWS_157286860_Browser (Mi*OWS_157286860_Project Man*OWS_157286861_admin
*OWS_157286861_Administrat*OWS_157286861_Browser (Mi*OWS_157286861_Project
Man
*OWS_157286861_Team Member*OWS_157286863_admin
*OWS_157286863_Administrat
*OWS_157286863_Browser (Mi*OWS_157286863_Project Man*OWS_157286863_Team
Member
*OWS_157286865_admin *OWS_157286865_Administrat*OWS_157286865_Browser
(Mi
*OWS_157286865_Project Man*OWS_157286958_admin
*OWS_157286958_Administrat
*OWS_157286958_Browser (Mi*OWS_157286958_Project Man*OWS_157286958_Team
Member
*OWS_157286960_admin *OWS_157286960_Administrat*OWS_157286960_Browser
(Mi
*OWS_157286960_Project Man*OWS_157286960_Team Member*OWS_157286963_admin
*OWS_157286963_Administrat*OWS_157286963_Browser (Mi*OWS_157286963_Project
Man
*OWS_157286963_Team Member*OWS_157286964_admin
*OWS_157286964_Administrat
*OWS_157286964_Browser (Mi*OWS_157286964_Project Man*OWS_157286966_admin
*OWS_157286966_Administrat*OWS_157286966_Browser (Mi*OWS_157286966_Project
Man
*OWS_157286966_Team Member*OWS_157286967_admin
*OWS_157286967_Administrat
*OWS_157286967_Browser (Mi*OWS_157286967_Project Man*OWS_157286967_Team
Member
*OWS_157287059_admin *OWS_157287059_Administrat*OWS_157287059_Browser
(Mi
*OWS_157287059_Project Man*OWS_157287065_admin
*OWS_157287065_Administrat
*OWS_157287065_Browser (Mi*OWS_157287065_Project Man*OWS_157287065_Team
Member
*OWS_157287067_admin *OWS_157287067_Administrat*OWS_157287067_Browser
(Mi
*OWS_157287067_Project Man*OWS_157287068_admin
*OWS_157287068_Administrat
*OWS_157287068_Browser (Mi*OWS_157287068_Project Man*OWS_157287068_Team
Member
*OWS_157287161_admin *OWS_157287161_Administrat*OWS_157287161_Browser
(Mi
*OWS_157287161_Project Man*OWS_157287161_Team Member*OWS_157287163_admin

The groups should look like

OWS_1382446396_admins
server 8081 admins....

Thx


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
R

Ritchie

LWG said:
I have a server that has 100 local groups configured. What I need to do is
parse the list to a file then push them back into another server. Is that
possible?

If you're poor, you might try something like this to create the list:-

@echo off & setlocal ENABLEEXTENSIONS
call :EnumLG
goto :EOF

:EnumLG
set "cmd=net localgroup^|findstr/b /c:"*""
for /f "tokens=1-3 delims=*" %%a in ('%cmd%') do (
for %%d in ("%%a" "%%b" "%%c") do call :doit %%d)
goto :EOF

:doit
setlocal
set "b=%1"
set "a=%b: "="%"
if %a%==%b% (endlocal & (if not %b%=="" (echo/[%b:"=%])) & goto :EOF)
endlocal & call :doit %a% %2 & (goto :EOF)
 
M

Matthias Tacke

Ritchie said:
If you're poor, you might try something like this to create the list:-
[snip]

I extended the good solution from Ritchie a bit do include
also the users belonging to each group. The output of
"net localgroup username" includes some crap lines, So
you can't automate further without doing an amount of
textreplacements.

But as a documentation for the poor it might be useful.

2 marked lines must be put one line in the batch file

hth
Matthias

***********GrpUsrLs.bat********************
@echo off & setlocal ENABLEEXTENSIONS
echo %date% %time% Group-User-List >GrpUsrLs.txt
call :ruler
del Grp-List.txt
call :EnumLG
type grp-list.txt >> GrpUsrLs.txt
call :ruler
for /F %%f in (grp-list.txt) do (
net localgroup %%f >>GrpUsrLs.txt
call :ruler
)
echo *** Group-List is in File Grp-List.txt ***
echo *** Group-User-List is in file GrpUsrLs.txt ***
goto :EOF

:EnumLG
set "cmd=net localgroup^|findstr/b /c:"*""
for /f "tokens=1-3 delims=*" %%a in ('%cmd%') do (
for %%d in ("%%a" "%%b" "%%c") do call :doit %%d)
goto :EOF

:doit
setlocal
set "b=%1"
set "a=%b: "="%"
if %a%==%b% (endlocal & (if not %b%==""
(echo %b:"=%>>Grp-List.txt)) & goto :EOF)
:: *** concatenate the above 2 lines into one ***
endlocal & call :doit %a% %2 & (goto :EOF)

:ruler
echo =======================================
========================================>>GrpUsrLs.txt
:: *** concatenate the above 2 lines into one ***
goto :EOF
 
R

Ritchie

Ritchie said:
endlocal & call :doit %a% %2 & (goto :EOF)

BTW, the %2 is completely redundant (remnant of MK I), so the line
above can be written as:-

endlocal & call :doit %a% & (goto :EOF)

BTW BTW, if you edit the ECHO statement in the :doit routine, it can
generate the commands required to create the new groups:-

:doit
setlocal
set "b=%1"
set "a=%b: "="%"
if %a%==%b% (
endlocal & (if not %b%=="" (
echo/net localgroup "%b:"=%" /add)
) & (goto :EOF)
)
endlocal & call :doit %a% & (goto :EOF)
 
A

Adam Wood

lgovedi1 said:
I have a server that has 100 local groups configured. What I need to do is
parse the list to a file then push them back into another server. Is that
possible?

You would have to use a separate utility/program to parse the data.
It's relatively simple with Perl...

Alternatively, how about launching the Local Users and Groups MMC scanp-
in, going to Groups, removing all but the name column (View menu) and
then exporting the list (right-click on "Groups" in the tree view).
 
Top