0

I am trying to write a batch that will copy the names of the profile folders to a txt file, then take each line (profile) and query ad with it. the two problems I seem to be having are:

  1. it says there is a syntax error in the way I wrote my for loop
  2. if I break it down for debugging, the loop seems to just set the variable over and over, then use the final value only to perform the commands in the subscripts
@echo off

@setlocal enabledelayedexpansion
pushd "c:\documents and settings"

mkdir c:\pulls
copy \\mint\testfolder\forfiles.exe c:\pulls\
copy \\mint\testfolder\psexec.exe c:\pulls\
rem call \\mint\testfolder\copy.bat c:\pulls\
set queryid=
set checkid=

rem finds all profiles that have been logged into in the last 18 months

c:\pulls\forfiles.exe /p "c:\documents and settings\" /d -540 /c "cmd /c if @ISdir==true deltree @isdir"

dir/b > "c:\documents and settings\profiles.txt"

%queryid% > "c:\documents and settings\tmp.txt"

rem active directory query

:adquery

for /f  "tokens=*" %%n IN ("c:\documents and settings\profiles.txt") do (
    set queryid=%%n
    call :sub
)


goto :end

:sub

c:\pulls\psexec.exe \\computer-u domain\user -p password dsquery user -name %queryid%     > "c:\documents and settings\tmp.txt"
set /p checkid= < "c:\documents and settings\tmp.txt"
del "c:\documents and settings\tmp.txt"


::checks to see if variable is an empty string

if [!%checkid%==!] goto :process1

if [%checkid%==] %queryid% >> c:\documents and settings\final.txt

goto :eof

:process1

c:\pulls\psexec.exe \\computer -u domain\user -p password dsquery user -name %queryid%     -desc *termed* > "c:\documents and settings\tmp.txt"
set /p checkid= < "c:\documents and settings\tmp.txt"
del "c:\documents and settings\tmp.txt"

::checks to see if variable is an empty string

if [!%checkid%==!] goto :amending
if [%checkid%==] goto :process2

goto :eof

:process2

c:\pulls\psexec.exe \\computer -u domain\user -p password dsquery user -name %queryid%     -disabled > "c:\documents and settings\tmp.txt"
set /p checkid= < "c:\documents and settings\tmp.txt"
del "c:\documents and settings\tmp.txt"

::checks to see if variable is an empty string

if [!%checkid%==!] goto :amending

goto :eof

:amending

%checkid% >> "c:\documents and settings\final.txt"

 goto :eof

:end

 notepad.exe "c:\documents and settings\final.txt"

del c:\pulls /y

del "c:\documents and settings\profiles.txt"

del "c:\documents and settings\final.txt"

rem copies selected profiles

rem c:\pulls\copy.bat

1 Answer 1

1

I haven't traced your entire logic to see if you have any other problems. But I have identified the problem with your FOR /F loop.

You are trying to read a file, but your IN() clause is double quoted, so it is interpreted as a string instead of a file name. (Type FOR /? for help on FOR command). You want to use double quotes because your path includes spaces, but you need it to be interpreted as a file name - that is what the USEBACKQ option is for!

for /f  "usebackq tokens=*" %%n IN ("c:\documents and settings\profiles.txt") do ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.