Sample Script - Get the Legacy Exchange DN from AD
During a recent Exchange 5.5 to 2003 maibox migration, I needed to have quick and easy access to the Legacy Exchange DN (AKA the Obj-Dist-Name in Exchange 5.5). We use the Zantaz EAS (Exchange Archive System) here, and it binds to MB's in the GAL through this field.
The ADUC (Active Directory Users and Computers) MMC doesn't display this field, and opening up ldp.exe takes waaay too much time.
So, in typical impatient geek fashion, I wrote a quick command line script to grab the field out of AD.
This script requires adfind.exe from Joeware.net. Joe Richards has some great freeware applications so check his site out.
In this script I grab three useful fields
1. User DN (Distinguished Name). I grab this just so I can find out if the user account is sitting in the _Disabled account OU. This outputs in the format:
dn:CN=Seaman\, John,OU=ServerAdmins,OU=PA,DC=root,DC=mydomain,DC=com
2. HomeMDB. This way I know at a glance which MB server they're on.
3. LegacyExchangeDN. This outputs in the format:
/O=MyExchOrgName/OU=PA/CN=RECIPIENTS/CN=SEAMANJ
ADfind is an extremely powerful tool, and I'm actually grabbing all the fields through the LDAP call and just filtering out those I'm interested in, so you can tweak the find statement and grab whatever info you're looking for.
Notes:
* As coded, this script searches on the samAccountName, AKA NT user ID. More complex scripting could be added for a "like" search.
* The batch script has the DC and base hard coded. Be sure to modify those before running the first time..
* This was a quick and dirty script, so we don't vet the input text.
Download the sample script here, or copy from below.
::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
echo.
echo Getting legacy exchange DN for user %1...
echo.
::REM Fix the base and DC fields for your domain.
set _base=dc=root,dc=mydomain,dc=com
adfind -h domain_controller -b %_base% -f "samAccountName=%1" >_getOdn.out.txt
echo.
echo DN............................:
echo.
type _getOdn.out.txt | find "dn:CN="
echo.
echo.
echo.
echo HomeMDB.......................:
echo.
type _getOdn.out.txt | find "homeMDB:"
echo.
echo.
echo.
echo legacyExchangeDN..............:
echo.
type _getOdn.out.txt | find "legacyExchangeDN:" >_getOdn.odn.txt
type _getOdn.odn.txt | t upper
echo.
echo.
::REM Pause here so you can kick this off from the run bar if desired
pause
:EOF
::REM ----------------- End sample batch script -----------------------------

Sample Script - Custom Attribute yields easier LDAP searching in ADUC »
Search