This is an old revision of the document!


LDAP, CSVDE & LDIFDE

Example Return all users who have a name Gerry

dsquery user -name Gerry*

Example Return all users who have a login name is cuicldap

dsquery user -samid cuicldap

Note: You cannot use CSVDE for modifying accounts, only for exporting or creation.
To modify accounts you need to use the LDIFDE command line tool.

Install The Active Directory Lightweight Directory Service Role (AD LDS) on your W2008R2 / W2012 Server
Or Download and install AD LDS for Windows 7


https://msdn.microsoft.com/en-us/library/aa772141(v=vs.85).aspx
https://technet.microsoft.com/en-us/library/cc732101(v=ws.11).aspx


csvde -f ADusers-Phone-Details.txt -r "(&(objectClass=user)(objectCategory=person))" -l "DN, objectClass, sAMAccountName, givenName, sn, displayName, telephoneNumber, ipPhone, msRTCSIP-USerEnabled, msRTCSIP-PrimaryUserAddress, department, extensionAttribute8, extensionAttribute9, manager, mobile, streetAddress, wWWHomePage, whenCreated, mail"

Example Filter

(&(&(objectclass=user)(telephonenumber=*))(sAMAccountName=alice))

Example - export users with a phone number

csvde -f ADusers-Phone-Details.txt -r "(&(objectclass=user)(telephonenumber=*))" -l "DN, objectClass, sAMAccountName, givenName, sn, displayName, telephoneNumber, mail, ipPhone, msRTCSIP-USerEnabled, msRTCSIP-PrimaryUserAddress, department, manager, mobile, streetAddress, wWWHomePage, whenCreated"
ldifde -r "(&(objectClass=user)(objectCategory=person))" -f export.ldf -l "ipPhone"

Sample Output from Exported file

dn: CN=Alice Anderson,OU=Users,OU=Accounts,DC=ucce9,DC=lab,DC=orourke,DC=tv
changetype: add
ipPhone: +35315551234

dn: CN=Supervisor Sarah,OU=Users,OU=Accounts,DC=ucce9,DC=lab,DC=orourke,DC=tv
changetype: add

Note on LDF file format. You need a “-” between modifications and it also requires a blank line following it, but only for the next user - see sample import file.

Step 1 Export User Data into CSV file format

csvde -f ADusers-Phone-Details-01.txt -r "(&(objectClass=user)(objectCategory=person))" -l "telephoneNumber,ipPhone"

Step 2 Update data and keep only the entries you want to modify - as in below CSV file format.
Filename: ADusers-Phone-Details-02.txt

DN,telephoneNumber,ipPhone
"CN=Alice Anderson,OU=Users,OU=Accounts,DC=ucce9,DC=lab,DC=orourke,DC=tv",12021,+35315551234
"CN=Bob Brown,OU=Users,OU=Accounts,DC=ucce9,DC=lab,DC=orourke,DC=tv",12022,+35316661005

Step 3 - create the template file for Log Parser (be care not to have any unwanted spaces in the template file)
Note: The log parser, removes the '+' sign contained in the CSVDE file, so I had to add it back (to ipPhone) within the template file.
Filename: AD-Telephone-LDF-Template.tpl

<LPBODY>
dn: %DN%
changetype: modify
replace: telephoneNumber
telephoneNumber: %telephoneNumber%
-
replace: ipPhone
ipPhone: +%ipPhone%
-
</LPBODY>

** Step 4 - Create your LDIFDE file from your CSV file, using Log Parser as per below example**

type ADusers-Phone-Details-02.txt | logparser "SELECT * FROM STDIN" -i:CSV -o:tpl -tpl:AD-Telephone-LDF-Template.tpl -q:on -stats:off > adusers-phone-details-02.ldf

** Step 5 - review your LDF file
**Filename:
adusers-phone-details-02.ldf


dn: CN=Alice Anderson,OU=Users,OU=Accounts,DC=ucce9,DC=lab,DC=orourke,DC=tv
changetype: modify
replace: telephoneNumber
telephoneNumber: 12021
-
replace: ipPhone
ipPhone: +35315551234
-

dn: CN=Bob Brown,OU=Users,OU=Accounts,DC=ucce9,DC=lab,DC=orourke,DC=tv
changetype: modify
replace: telephoneNumber
telephoneNumber: 12022
-
replace: ipPhone
ipPhone: +35316661005
-

Step 6 - Import your LDF file to AD and review Logs

ldifde -i -f adusers-phone-details-02.ldf -j "C:\Program Files (x86)\Log Parser 2.2"
  • vendors/microsoft/ad/csvde.1526583406.txt.gz
  • Last modified: 2018/05/17 19:56
  • by gerardorourke