Export Usernames and Email Addresses
Hi, I’m running an Active directory successfully since past 2 years. Due to some reasons now I want to export usernames and email addresses from a particular user group. I know I can do this using NET GROUP command in DOS but that will only export Contacts and not the email address, right? So can anyone please tell me what would be the better way to export both email and contacts? Can it be done with LDAP?
Please help.
Re: Export Usernames and Email Addresses
Yes, you can use LDAP to some extent but as per me Win2003 DSGet command would be far better than that of Net Commands. It should be like
DSGet user /?
( -email = address seems promising)
You may also be asked for combining the preliminary DSQuery User in order to get all of the User names for processing by DSGet.
Re: Export Usernames and Email Addresses
Type the following at a CMD.EXE window for an example:
dsquery group -name "Domain Admins"|dsget group -members|dsget user -samid -email -display
See if it helps.
Re: Export Usernames and Email Addresses
As i can assume your groups contain contacts, i think running the following script may help you out:
@echo off
if {%1}=={} @echo Syntax: GGME Group&goto :EOF
setlocal ENABLEDELAYEDEXPANSION
set grp=%1
set grp=%grp:"=%
for /f "Tokens=*" %%a in ('dsquery group -name "%grp%"') do (
if %%a NEQ "" for /f "Tokens=*" %%x in ('dsget group %%a -samid^|Findstr /V /L /C:"dsget succeeded"') do set gdn=%%x#
set gdn=!gdn: #=!
if %%a NEQ "" for /f "Tokens=*" %%b in ('dsget group %%a -members -expand') do (
set user=%%b
set user=!user:"=!
set ok=N
set dn=
set mail=
if %%b GTR " " for /f "Tokens=1*" %%c in ('dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(distinguishedName=!user!))" -attr displayName mail -L -LIMIT 0') do (
if /i "%%c" EQU "displayName:" set dn=%%d&set ok=Y
if /i "%%c" EQU "mail:" set mail=%%d
)
if "!ok!" EQU "Y" if "!dn!" NEQ "" @echo "!gdn!" "!dn!" "!mail!"
)
)
endlocal
goto :EOF