Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Code that moved AD users to specific OU. Can the same code be changed to move Contacts.

Avatar of bsharath
bsharathFlag for India asked on
Scripting LanguagesWindows BatchShell Scripting
9 Comments1 Solution421 ViewsLast Modified:
Hi,

Code that moved AD users to specific OU. Can the same code be changed to move Contacts.
Can anyone help me with this.

Regards
Sharath
:: SCRIPT START
@ECHO OFF
SETLOCAL EnableDelayedExpansion

:: Following variables required to be set with actual values
SET NewOU=TempOU

IF EXIST UserMoveRpt.txt DEL /F /Q UserMoveRpt.txt
ECHO %NewOU%|FIND /I "OU=">NUL
IF NOT ERRORLEVEL 1 (
    DSQuery OU "%NewOU%" 2>NUL |FIND /I "OU=" >NUL
    IF NOT ERRORLEVEL 1 (DSQuery OU "%NewOU%" >OUTmpVar.txt &SET /P OUDN=<OUTmpVar.txt
    ) ELSE (ECHO Invalid OU distinguished name. &Goto :EndScript)
)ELSE (
    DSQuery OU -Name "%NewOU%" |FIND /I "OU=" >NUL
    IF NOT ERRORLEVEL 1 (DSQuery OU -Name "%NewOU%" >OUTmpVar.txt &SET /P OUDN=<OUTmpVar.txt
    )ELSE (ECHO Invalid OU Name. &Goto :EndScript)
)

FOR /F "delims=*" %%u IN ('TYPE UserIDs.txt') DO (
      ECHO Processing: %%u
      DSQuery User -samID "%%u" |Find /I "CN=" >NUL
      IF NOT ErrorLevel 1 (
            DSQuery User -samID "%%u" |DSMove -newparent !OUDN! >>UserMoveRpt.txt
      )ELSE (ECHO *ERROR* '%%u' Not Found in Active Directory.))

ECHO.&ECHO Script complete. Check 'UserMoveRpt.txt' file.
:EndScript
IF EXIST OUTmpVar.txt DEL /F /Q OUTmpVar.txt
ENDLOCAL
EXIT /B 0
:: *** SCRIPT END ***