JSI Tip 8916. How can I export local group domain membership and import it to another 'server'?

I have scripted XLCLGRP.BAT to export local group domain membership, and ILCLGRP.BAT to import it to a another computer.

The syntax for using XLCLGRP.BAT is:

XLCLGRP filename

Where filename is the name of a file that will contain domain membership in local groups.

The syntax for using ILCLGRP.BAT is:

ILCLGRP filename

Where filename is the name of the file generated by XLCLGRP.BAT.

NOTE: ILCLGRP.BAT uses XLCLGRP.BAT, so both files should be stored in the same folder.

XLCLGRP.BAT contains:

@echo off
if \{%1\}

\{\} @echo Syntax XLCLGRP FileName setlocal ENABLEDELAYEDEXPANSION set file=%1 if exist %file% del /q %file% set wrk1="%TEMP%\XLCLGRP_%RANDOM%.TMP%" set wrk2="%TEMP%\XLCLGRP_%RANDOM%.TMP%" if exist %wrk1% del /q %wrk1% if exist %wrk2% del /q %wrk2% set fnd0=FIND "*" set fnd1=FIND /V "The command completed successfully." set fnd2=FIND "\" set fnd3=FIND /V "NT AUTHORITY\" for /f "Tokens=*" %%g in ('net localgroup^|%fnd0%^|%fnd1%') do ( set work=%%g set group=!work:~1! @echo 1 "!group!">>%wrk1% for /f "Tokens=*" %%m in ('net localgroup "!group!"^|%fnd1%^|%fnd2%^|%fnd3%') do ( @echo 2 "!group!" "%%m">>%wrk1% ) ) sort %wrk1% /O %wrk2% del /q %wrk1% for /f "Tokens=1*" %%a in ('type %wrk2%') do ( @echo NET LOCALGROUP %%b /ADD>>%file% ) del /q %wrk2% endlocal

ILCLGRP.BAT contains:

@echo off
if \{%1\}\{\} @echo Syntax ILCLGRP FileName&goto :EOF
if not exist %1 @echo ILCLGRP %1 - NOT found.&goto :EOF
set file=%1
set fnd=FINDSTR /I /V /L /G:%wrk%
call XLCLGRP %wrk%
for /f "Tokens=*" %%a in ('type %file%^|%fnd%') do (
del /q %wrk%

TAGS: Windows 8
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.