Support Forums

Description field line breaks when exporting in vbscript

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.
User avatar
jvierra
Posts: 9702
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Description field line breaks when exporting in vbscript

Postby jvierra » Thu Jan 02, 2014 3:17 pm

I stripped you code to the minimum. IT works as expected for description. Try it.

VBScript Code
Double-click the code block to select all.
strBase = "<LDAP://dc=testnet,dc=local>"

strFilter = "(&(objectCategory=person)(objectClass=user))"
strAttributes = "distinguishedName,samAccountName,WhenCreated,WhenChanged,Description,givenName,SN,useraccountcontrol"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery

Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open = "Active Directory Provider"
Set adoRecordset = adoConnection.Execute( strQuery )
Do Until adoRecordset.EOF
desc = adoRecordset.Fields("Description").Value
if IsArray(desc) Then
WScript.Echo Join(desc,"|")
Else
If Not IsNull(desc) THen
WScript.Echo desc
Else
Wscript.Echo "DESCRIPTION_IS_NULL"
End If
End If
adoRecordset.MoveNext
Loop
User avatar
new_user
Posts: 157
Joined: Wed May 30, 2007 7:01 am

Re: Description field line breaks when exporting in vbscript

Postby new_user » Thu Jan 02, 2014 4:04 pm

I believe that worked but is difficult to read without the other attributes. Of course I added that function to my original code commenting out the old and cannot just output the "desc" variable that you have echo'ing. How do I assign another to it so I can just write it out with the other output?
User avatar
jvierra
Posts: 9702
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Description field line breaks when exporting in vbscript

Postby jvierra » Thu Jan 02, 2014 4:11 pm

Just assign it instead of outputting it. The value desc contains the simple string and the results of "Join" is the compound (catenated) string.
User avatar
new_user
Posts: 157
Joined: Wed May 30, 2007 7:01 am

Re: Description field line breaks when exporting in vbscript

Postby new_user » Thu Jan 02, 2014 4:42 pm

Such as below: This throws it to the next line instead of the same:

desc = adoRecordset.Fields("Description").Value
if IsArray(desc) Then
StrDescNew = Join(desc,"|")

Else
If Not IsNull(desc) THen
StrDescNew1 = desc

Else
StrDescNew = "DESCRIPTION_IS_NULL"
End If
End If
User avatar
jvierra
Posts: 9702
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Description field line breaks when exporting in vbscript

Postby jvierra » Thu Jan 02, 2014 4:54 pm

Sorry but I do not understand what you are posting. Why are yo using two variable names?

This is what it should be.

VBScript Code
Double-click the code block to select all.
desc = adoRecordset.Fields("Description").Value
If IsArray(desc) Then
strDescNew = Join(desc,"|")
Else
If Not IsNull(desc) Then
strDescNew = desc
Else
strDescNew = "DESCRIPTION_IS_NULL"
End If
End If


You need to try to keep the formatting so you can see how the code works.
User avatar
new_user
Posts: 157
Joined: Wed May 30, 2007 7:01 am

Re: Description field line breaks when exporting in vbscript

Postby new_user » Thu Jan 02, 2014 5:01 pm

Copying your last post which looks to be a duplicate of mine yields the same output issue. Assigning a new variable so I can utilize it to write the output per your post. I do have it formatted its just not transferring over via copy and paste.
User avatar
jvierra
Posts: 9702
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Description field line breaks when exporting in vbscript

Postby jvierra » Thu Jan 02, 2014 5:13 pm

new_user wrote:Copying your last post which looks to be a duplicate of mine yields the same output issue. Assigning a new variable so I can utilize it to write the output per your post. I do have it formatted its just not transferring over via copy and paste.


You need to use the editor tags for VBScript.

I do not understand your issue. The description field is and always has been an array. It is possible for some third party tools and some badly written scripts to put nulls and other illegal characters into the descri0ption field. I cannot help you fix that.

If you are running a Unicode version of the command prompt or are running in a different language then you can have issues. That is up to you to resolve. The VBScript and the LDAP is correct and works cor4recctly on all systems that are set up correctly.

I recommend using the CSVDE utility to dump the user data. Look closely at its output.

If someone has stuffed line breaks or nulls into the description field you will have to fix that in order to get the field to behave correctly.
User avatar
new_user
Posts: 157
Joined: Wed May 30, 2007 7:01 am

Re: Description field line breaks when exporting in vbscript

Postby new_user » Thu Jan 02, 2014 5:19 pm

Lets try this again. They I am sure pasted contents from a ticketing system into the Description field. The normal method I use to grab that does not work in this case because of this, hence my original post. The change in function with your wscript.echo seems to help. I wanted to plug that into my original code. Instead of wscript.echo I wanted to assigned something to the array desc output in order to put it in my current write statement with all of the other ouput. I tried that, it did not work and went back to not putting all if the data for that field on the same line so I posted back to ensure I was actually doing that correctly......
User avatar
jvierra
Posts: 9702
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Description field line breaks when exporting in vbscript

Postby jvierra » Thu Jan 02, 2014 6:18 pm

I am sorry. If someone dumped crap into the description field you can only replace it or contact a consultant and pay them to fix this for you.

I do this all of the time. It is not something that can be done in a forum. You need a trained specialist to help you remedy this situation.

Sorry.
User avatar
new_user
Posts: 157
Joined: Wed May 30, 2007 7:01 am

Re: Description field line breaks when exporting in vbscript

Postby new_user » Thu Jan 02, 2014 6:21 pm

So there is no way to pull the data from the description field into one line of output with a vbscript, so it does not break to a new line?

I thought your new concat function was doing that with the echo statement, i was trying to change from echo to a var name so I could add it to my objFile.WriteLine statement with all of the other variables.

Return to “VBScript”

Who is online

Users browsing this forum: No registered users and 2 guests