0

I am using CSVDE to export some user info out of AD. I need to loop over several domain controllers and export data from each one to a separate csv file. To do so, I am using the following batch script (only 1 domain controller / file is displayed for simplicity):

ECHO %time%

@ECHO OFF

SET userName=SomeLogin
SET pass=SomePassword
SET domain=SomeDomain

SET columnName=-l givenname,lastLogon,userAccountControl,lastLogonTimestamp,sn,userPrincipalName,displayname,mail,samaccountname,pwdLastSet,whenCreated,whenChanged SET filter="(&(objectClass=User)(objectCategory=Person))"

SET len=1
SET data[0].file=some_file.csv
SET data[0].DC=someIP

SET i=0
:LOOP
IF %i% equ %len% GOTO :EOF

SET cur.file=
SET cur.DC=
FOR /f "usebackq delims==. tokens=1" %%j IN (`SET data[%i%]`) DO (
    SET cur.%%k=%%l
)
csvde -f %cur.file% -r %filter% %columnName% -s %cur.DC% -b %userName% %domain% %pass% -u

SET /a i = %i% + 1

@ECHO ON
ECHO %time%

When I run this script, I get the following error:

Invalid Parameter: Bad argument '(&(objectClass=User)(objectCategory=Person))'

When I run CSVDE outside of this script (i.e., outside of a loop), it runs just fine. So, it must have something to do with the fact that it's in a loop. But, I can't figure out why and how to resolve it. What do I need to change to resolve this issue?

skyline01
  • 1,919
  • 8
  • 34
  • 55
  • Your `FOR` command is only asking for 1 TOKEN which gets assigned to `j`. So the for variables `k` and `l` are not populated. So this command: `SET cur.%%k=%%l` isn't doing what you think it is doing. – Squashman Oct 27 '17 at 17:53
  • And as far as I can see the variables `cur.file` and `cur.DC` will always be empty. You never assign anything to them. So your `-f` and `-s` options will have nothing in you `csvde` command. – Squashman Oct 27 '17 at 17:56

0 Answers0