0

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
newbie
  • 11
  • 1
  • 4
  • obviously the reason is that %%g and %dusercn% do not have the literals that work. I can see that `dusercn` is initialized to blank. But you tried to set it, probably, to the output of dsquery command. You'll need to fix that with a FOR command. – PA. Jun 06 '12 at 17:14
  • alex - i dont quite understand your response. as you said above i set dusercn to null and then assigned to output from dsquery which is cn path of destination user. so shouldnt dusercn be assigned with that value when i use that in for command? – newbie Jun 07 '12 at 16:02
  • no, it will not, to assign the output of a command into a variable, you cannot just set it as you would in other shell scripting languages; in BAT files you need to use the FOR command. – PA. Jun 08 '12 at 05:33
  • i changed my for loop to what you suggested but it still doesnt work. here is what i changed to, **for /f "tokens=*" %%g in ('dsquery user -samid %susername% ^|dsget user -memberof') do ( echo %%g %dusercn%=dsquery user -samid %dusername% dsmod group %%g -addmbr %dusercn% echo %dusercn% )** – newbie Jun 13 '12 at 11:02
  • thank you everyone, i figured it out finally...i dont know how to post the script that worked for me. someone please let me know so i can post it so it could be helpful to other newbies like me. ;-) – newbie Jun 13 '12 at 11:55

1 Answers1

0

thanks for all your help. 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
Stewbob
  • 16,759
  • 9
  • 63
  • 107
newbie
  • 11
  • 1
  • 4