?
Solved

change output of ldif file

Posted on 2013-01-14
5
Medium Priority
?
284 Views
Last Modified: 2013-01-16
Been searching the topics and haven't found anything and thought I would ask. I am looking for help. I have output in an ldif file that I need to read the SN and the givenName and overwrite what is in the CN with (givenName SN). This is for an ever growing number of users.

example
from
cn: BLAH
sn: LastName
givenName: FirstName

to
cn: Firstname Lastname
sn: LastName
givenName: FirstName
0
Comment
Question by:aev2061
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:terencino
ID: 38778386
Hi I got this to work on the limited info I had for your LDIF file, can you test it and let me know how you go? It uses the FileSystemObject to read and write the file and the Mid function to modify the CN line. I'm not sure how LDIF files end (to stop the loop with the AtEndOfStream property), so it will probably crash at the end. If so could probably get round it with On Error
...Terry
Option Explicit
Dim objFSO, objImport, objExport
Dim Line1, Line2, Line3, Line4
Dim strImport, strExport
Set objFSO = CreateObject("Scripting.FileSystemObject")
strImport = "C:\test.ldf"
strExport = "C:\test_fix.ldf"
Set objImport = objFSO.GetFile(strImport)
Set objImport = objFSO.OpenTextFile(objImport, 1)
Set objExport = objFSO.CreateTextFile(strExport)
Do Until objImport.AtEndOfStream
	Line1 = objImport.ReadLine
	Line2 = objImport.ReadLine
	Line3 = objImport.ReadLine
	Line4 = objImport.ReadLine
	objExport.WriteLine "cn: " & Mid(Line3,12,200) & " " & Mid(Line2,5,200)
	objExport.WriteLine Line2
	objExport.WriteLine Line3
	objExport.WriteLine Line4
Loop
objImport.Close
objExport.Close

Open in new window

0
 

Author Comment

by:aev2061
ID: 38779567
Thanks for your response. Below is an output of an ldf file so you can see how 2 exports would look like and the file ends just like it is. I guess it would have help had I put a better example in my first post. As you can see better now I am try to replace the
(cn: Person1) with (cn: Bill Smith) and likewise the (cn: Person2) with (cn: Sandy Jones), etc, etc...

dn: CN=BLAH1,OU=OFFICEUSR,OU=OFFICE1,OU=AAA,OU=BB,DC=city,DC=state,DC=com
#changetype: add
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: user
cn: Person1
sn: Smith
givenName: Bill
displayName: Smith, Bill
sAMAccountName: Person1
userPrincipalName: Person1@city.state.com
mail: Bill.Smith@state.com

dn: CN=BLAH2,OU=OFFICEUSR,OU=OFFICE1,OU=AAA,OU=BB,DC=city,DC=state,DC=com
#changetype: add
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: user
cn: Person2
sn: Jones
givenName: Sandy
displayName: Jones, Sandy
sAMAccountName: Person2
userPrincipalName: Person2@city.state.com
mail: Sandy.Jones@state.com
0
 
LVL 16

Accepted Solution

by:
terencino earned 1000 total points
ID: 38781015
Ok, the coding is a bit different but works fine for that sample, let me know how you go
...Terry

Option Explicit
Dim objFSO, objImport, objExport
Dim LDIFGroup
Dim strImport, strExport, i , a
Set objFSO = CreateObject("Scripting.FileSystemObject")
strImport = "C:\Users\tharvey.BBIDBCT\SkyDrive\EE\test.ldf"
strExport = "C:\Users\tharvey.BBIDBCT\SkyDrive\EE\test_fix.ldf"
Set objImport = objFSO.GetFile(strImport)
Set objImport = objFSO.OpenTextFile(objImport, 1)
Set objExport = objFSO.CreateTextFile(strExport)
On Error Resume Next
Do Until objImport.AtEndOfStream
  For i = 0 To 13 'Load 14 lines into a group
    If i = 0 Then
      LDIFGroup = objImport.ReadLine
    Else
      LDIFGroup = LDIFGroup & "|" & objImport.ReadLine
    End If
  Next 

a = Split(LDIFGroup, "|") 'convert the group to an array and split lines out

  For i = 0 To 13 'write lines to new file
    If i = 6 Then
      objExport.WriteLine "cn: " & Mid(a(8),12,200) & " " & Mid(a(7),5,200)
    Else
      objExport.WriteLine a(i)
    End If
  Next 	
Loop
objImport.Close
objExport.Close

Open in new window

0
 

Author Comment

by:aev2061
ID: 38782362
That works and helps me learn a little more on how this works!

Thanks
0
 

Author Closing Comment

by:aev2061
ID: 38782366
Thanks for the help!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question