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.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 10 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Description field line breaks when exporting in vbscript

Post by jvierra »

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
Last visit: Tue May 06, 2014 5:46 pm

Re: Description field line breaks when exporting in vbscript

Post by new_user »

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?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Description field line breaks when exporting in vbscript

Post by jvierra »

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
Last visit: Tue May 06, 2014 5:46 pm

Re: Description field line breaks when exporting in vbscript

Post by new_user »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Description field line breaks when exporting in vbscript

Post by jvierra »

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
Last visit: Tue May 06, 2014 5:46 pm

Re: Description field line breaks when exporting in vbscript

Post by new_user »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Description field line breaks when exporting in vbscript

Post by jvierra »

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
Last visit: Tue May 06, 2014 5:46 pm

Re: Description field line breaks when exporting in vbscript

Post by new_user »

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......
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Description field line breaks when exporting in vbscript

Post by jvierra »

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
Last visit: Tue May 06, 2014 5:46 pm

Re: Description field line breaks when exporting in vbscript

Post by new_user »

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.
This topic is 10 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked