User Account Group Membership Copy

# membershipcopy.bat

@echo off
cls
rem set /p AdminID=Please Input Admin UserID:
rem set / AdminPassword=Please Input Admin Password:

Set /p CopyFrom=Copy From:
Set /p CopyTo=Copy To:

FOR /f "Tokens=*" %%a in ('dsquery user -samid %CopyTo%') DO Set CopyTo=%%a

IF NOT DEFINED CopyTo (
ECHO Could not find %CopyTo% in AD
GOTO :EOF
)

FOR /f "Tokens=*" %%a in ('dsquery user -samid %CopyFrom%') DO Set CopyFrom=%%a
IF NOT DEFINED CopyFrom (
ECHO Could not find %CopyFrom% in AD
GOTO :EOF
)

ECHO Copying groups from user %CopyFrom% to user %CopyTo%...
ping 127.0.0.1 -n 2 > nul
ECHO ===============================================================================
ECHO Copying groups from user %CopyFrom% to user %CopyTo%...

FOR /f "Tokens=*" %%a in ('dsget user %CopyFrom% -memberof') do (
dsmod GROUP %%a -addmbr %CopyTo% | find /i "dsmod succeeded:"
)
ECHO ===============================================================================
ping 127.0.0.1 -n 2 > nul
echo press any key to continue...
pause > nul
cls
exit
# groupCopy.ps1

import-module activedirectory
Do
{
$fromGroup = Read-Host -Prompt 'Copy From Group:'
$toGroup = Read-Host -Prompt 'Copy To Group:'
Add-ADGroupMember -Identity $toGroup -Members (Get-ADGroupMember -Identity $fromGroup -Recursive)
$flag = Read-Host -Promp 'Press Any Key = exit; C = Continue Copying...'
} while ($flag -match '[Cc]')

Leave a Reply

Your email address will not be published. Required fields are marked *