::REM ----------------- Begin sample batch script ----------------------------- @echo off cls ::REM Get Legacy Exchange DN from AD sample script ::REM By John Seaman, www.japan-page.net/batch ::REM (C)Copylefted under terms of the GNU / GPL ::REM This script will take a user name (samAccountName) and add the custom value specified below into the ::REM AD Custom Attribute field #3. A custom LDAP script can then search this field and select all users ::REM for the exchange attributes removal/migration/etc. ::REM Note: to see the field from ADUC, go to Exchange Advanced tab, choose Custom Fields. ::REM This script requires adfind.exe and admod.exe from from Joeware.net (http://www.joeware.net/win/free/tools/adfind.htm). ::REM Big thanks to Joe Richards !!! ::REM Usage call this script and append the user ID after it, updateLdap.cmd ::REM Or run a loop like the following.... ::REM for /f %%i in (userlist.txt) do call :processUser %%i ::REM pause ::REM goto :EOF ::REM Be sure to update the _baseDN field for your domain! ::REM Set variables set _dc=MyDomainController set _baseDN="OU=MyOuInActiveDirectory,DC=root,DC=MyDomain,DC=com" ::REM Create log file set _log=updateLdap.log ::REM Set the text to add to the custom field set _text=20080816migrate :processUser ::REM Start echo Now applying update to user $1... ::REM --------------------- ::REM Get username base DN: ::REM Time to get jiggy... adfind -b %_baseDN% -f "(&(objectcategory=user)(samAccountName=%1))" -dn >_out.txt type _out.txt | find "dn:" >_userDN.txt ::REM Fix the UserDN by nuking the first 3 characters... ::REM I use textTools32, replace with SED or your favorite text editor type _userDN.txt | t repl 'dn:' '' >_userDN1.txt for /f "delims=@" %%i in (_userDN1.txt) do echo User $1 DN is %%i >>%_log% ::REM ---------------------- ::REM Call ADmod and fix the field for /f "delims=@" %%i in (_userDN1.txt) do call admod.exe -h %_dc% -b "%%i" "extensionAttribute3::%_text%" -exterr >>%_log% echo %errorlevel% :EOF ::REM ----------------- End sample batch script -----------------------------