Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 doesn't 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.

any help would be awesome!!!

thank you.

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
share|improve this question
    
anyone help?? –  newbie Jun 13 '12 at 11:05

1 Answer 1

I am posting answer that worked for me. Hopefully it helps other newbies like me.

echo off
echo %date% at %time%

set /p susername=enter source user name:
set /P dusername=enter destination user name:

rem echo+ is used for new line. echo+
echo entered source user name: %susername%
echo entered destination user name: %dusername%
echo+

set dusercn=0
set lines=0

for /f "tokens=*" %%g in ('dsquery user -samid %susername% ^|dsget user -memberof') do (
    echo %%g
    dsquery user -samid %dusername% | dsmod group %%g -addmbr -c
    set /a lines=lines+1
)

echo+
echo+
echo **************
echo number of lines processed %lines%
echo script completed
echo **************
pause
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.