trying to copy security groups to a user using dsmod group utility in AD

Posted by newbie on Server Fault See other posts from Server Fault or by newbie
Published on 2012-06-06T15:53:40Z Indexed on 2012/06/06 16:42 UTC
Read the original article Hit count: 246

Filed under:

i am trying to create a batch file that asks to enter source samid and destination samid. then using dsquery and dsget find out what security groups source samid is assigned to and assign destination samid to those security groups using dsmod.

everything works except the dsmod group command. it doesnt do anything and batch file stops. if i literally put "CN=marketing,OU=test group,DC=abc,DC=com" instead of %%g and "CN=test1,OU=test group,DC=abc,DC=com" instead of %dusercn%, it works fine.

can anyone help with this? i have pasted my scrip here. this last small thing is killing me.


echo off

echo %date% at %time%

set /p susername=enter source user name:

set /P dusername=enter destination user name:

echo %susername%

echo %dusername%

set dusercn=

%dusercn%=dsquery user -samid %dusername%

echo %dusercn%

for /f "tokens=*" %%g in ('dsquery user -samid %susername% ^|dsget user -memberof') do (dsmod group %%g -addmbr %dusercn%)

echo completed

pause

© Server Fault or respective owner

Related posts about batch