Code that moved AD users to specific OU. Can the same code be changed to move Contacts.
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 OFFSETLOCAL EnableDelayedExpansion:: Following variables required to be set with actual valuesSET NewOU=TempOUIF EXIST UserMoveRpt.txt DEL /F /Q UserMoveRpt.txtECHO %NewOU%|FIND /I "OU=">NULIF 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.:EndScriptIF EXIST OUTmpVar.txt DEL /F /Q OUTmpVar.txtENDLOCALEXIT /B 0:: *** SCRIPT END ***
Hi, see if this works. It should read contact ids from a file called ContactIDs.txt
Rob.
:: SCRIPT START @ECHO OFF SETLOCAL EnableDelayedExpansion :: Following variables required to be set with actual values SET NewOU=TempOUIF EXIST ContactMoveRpt.txt DEL /F /Q ContactMoveRpt.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 ContactIDs.txt') DO ( ECHO Processing: %%u DSQuery Contact -samID "%%u" |Find /I "CN=" >NUL IF NOT ErrorLevel 1 ( DSQuery Contact -samID "%%u" |DSMove -newparent !OUDN! >>ContactMoveRpt.txt )ELSE (ECHO *ERROR* '%%u' Not Found in Active Directory.)) ECHO.&ECHO Script complete. Check 'ContactMoveRpt.txt' file. :EndScript IF EXIST OUTmpVar.txt DEL /F /Q OUTmpVar.txt ENDLOCAL EXIT /B 0 :: *** SCRIPT END ***