I have scripted AddDomGroupMembers.bat to add the domain users who are members of a local group to a global group. The syntax for using AddDomGroupMembers.bat is:

AddDomGroupMembers LocalGroup DomainGroup

You must run AddDomGroupMembers.bat on the computer where the local group is defined, or use PsExec to run it remotely.

AddDomGroupMembers.bat will:

- Check for the existence of the LocalGroup.

- Create the DomainGroup if it does not already exist.

- Add domain users who are members of the LocalGroup to the DomainGroup.

AddDomGroupMembers.bat contains:

@echo off
if \{%1\}

\{\} @echo Syntax: AddDomGroupMembers LocalGroup DomainGroup&goto :EOF
if \{%2\}

\{\} @echo Syntax: AddDomGroupMembers LocalGroup DomainGroup&goto :EOF
setlocal
set Localgroup=%1
set DomainGroup=%2
if exist "%temp%\group.bat" del /q "%temp%\group.bat"
set line=""
for /f "Tokens=2" %%a in ('net localgroup %LocalGroup%') do set line="%%a"
if %line% EQU "command" goto :OK
@echo Local Group NOT found.
endlocal
goto :EOF
:OK
set line=""
for /f "Tokens=2" %%a in ('net group %DomainGroup% /domain') do set line="%%a"
if not %line% EQU "command" @echo net group %domainGroup% /add /domain>"%temp%\group.bat"
for /f "Skip=6 Tokens=*" %%i in ('net LocalGroup %Localgroup%') do set line=%%i&call :parse
call "%temp%\group.bat"
endlocal
goto :EOF
:strip
set short=%name%#
set short=%short:  =%
set short=%short: #=#%
set short=%short:#=%
set user=%short%
set work=%user:\=%
if "%user%" EQU "%work%" goto :EOF
for /f "Tokens=1* Delims=\" %%m in ('@echo %user%') do set user="%%n"
set line=""
for /f "Skip=25 Tokens=2" %%a in ('net user %user% /domain') do set line="%%a"
if %line% EQU "command" @echo net group %domainGroup% %user% /add /domain>>"%temp%\group.bat"
goto :EOF
:parse
set name=%line:~0,25%
If /i "%name%" EQU "The command completed suc" goto :EOF
call :strip
set name=%line:~25,25%
if not "%name%" EQU "" call :strip
set name=%line:~50,25%
if not "%name%" EQU "" call :strip