Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading a text file and creating variables as strings

Status
Not open for further replies.

kokser

Programmer
Sep 25, 2009
90
DK
Long story short, I have a small vbscript that looks like this:
Code:
objshell.run "cmd /c ldifde -f temp.txt -s MyCompany -d ou=TestOU,dc=MyCompany,dc=local -r objectclass=user  -l name,samaccountname,proxyaddresses,mail,memberof,homedrive,homedirectory"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("h:\temp.txt", ForReading)
Const ForReading = 1
Dim arrFileLines()
i = 0
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
What it's suppose to do, is create a temporary text file with the information I need from my company AD. Then read the file (if this is neccesary) and create a variable for each attribute I have exported.

The temp.txt currently looks like this
Code:
dn: CN=Test User,OU=TestOU,DC=MyCompany,DC=local
changetype: add
memberOf: CN=TestGroup,OU=TestOU,DC=MyCompany,DC=local
name: TestUser
homeDirectory: \\Server\Dir$\TestUser
homeDrive: H:
sAMAccountName: TU
mail: tu@MyCompany.net
What i want it to do, is split those strings into 2 parts. I assume that I will need to make all the strings variables (As i mentioned above).

So I split 1 string variable into 2 string variables.
"Name: TestUser" >>"Name:" "TestUser"
and so on.


So to sum up; I need help with creating these variables and splitting them up. Any help and suggestions appreciated :)
 
might be simpler query LDAP directly rather than shelling out and writing / reading a txt file
 
Yes, this is what I thought also, I am googling around, but i can only find how to do it with Excel.
Can you hlep me with this?
 
'this might point you in the right direction?
Set oCommand = CreateObject("ADODB.Command")
Set oConnection = CreateObject("ADODB.Connection") '#
oConnection.Provider = "ADsDSOObject" '#
oConnection.Open = "Active Directory Provider" '#
oCommand.ActiveConnection = oConnection '#then Create a connection.
Set oRoot = GetObject("LDAP://RootDSE") '#
oCommand.Properties("Page Size") = 999
sdnsDomain = "dc=fsc,dc=net"
sQuery = "SELECT scriptPath, sAMAccountName, extensionAttribute2 FROM 'LDAP://fqdn.to.dc' WHERE objectClass = 'user'"
oCommand.commandtext = sQuery 'set the command text
oCommand.Properties("Page Size") = 999 'set the page size to allow for more than a 1000 records
Set oRs = oCommand.execute

'While Not oRS.EOF
If oRS.RecordCount = 1 Then 'loop throuugh users
For i = 0 To oRS.Fields.Count - 1
If oRS.Fields(i).Name = "extensionAttribute2" Then
'If oRS.Fields(i).Name = "scriptPath" Then
Msgbox oRS.Fields(i)
End If
Next
'oRS.MoveNext

Else


Msgbox "not found"

End If
'Wend

Set oRS = Nothing
Set oConnection = Nothing
Set oCommand = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top