Re: Formatting...



Not sure I follow you completely but to kill everything from the first comma
you should be able to use the mid function and instr function. If your
getting the comma's I would guess you are writing records to file that
doesnt need to be. You should first check if you can suppress this by
something like if EmailAddr or whatever your using

if emailaddr = "" then
' dont write it
else
' write the record
end if

Its hard for me to see the file your actually parsing due to word wrap but
as long as you can find something in common such as the excessive comma's
you should be able to parse them using the methed I explained. Worse case
senero open the file back up and then split the files at the comma's and
trash all blank fields.

Bryan



<dankennedy24@xxxxxxxxx> wrote in message
news:1161819578.573192.102100@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Funny enough, I think I solved my first problem by putting the vbcrlf
in front of the primary email address like this:

txtstream.write vbcrlf & Primary & ", "

Now when I run the script the output is like this:

primary1@xxxxxxxxxx, alias1@xxxxxxxxxx, alias2@xxxxxxxxxx, , , , , , ,
, , , , , , , ,
primary2@xxxxxxxxxx, alias3@xxxxxxxxxx, alias4@xxxxxxxxxx,
alias5@xxxxxxxxxx, , , , , , , , , , ,

How can I kill these extra commas? Each user could theoretically have
a different number of aliases so I can know how man to look for... is
there a way to tell the script to look for "m, ," and kill everything
from the first comma through the end of the line?

Thanks,
Dan


Its me Earnest T. wrote:
getting a vbcrlf at the end
EmailAddr = objMember.mail & vbcrlf

depending on where the commas are
EmailAddr = Replace(EmailAdd, ",", "")

Bryan

<dankennedy24@xxxxxxxxx> wrote in message
news:1161816012.312733.215330@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hey guys,
I have the following script which outputs a user's primary email
address followed by a comma, a space and then any aliases. My issue is
with formatting, at the end of each "record" I'd like to see a return
(vbcrlf) and then see the next record. I'd also like to see the
extraneous comma's taken out. Can anyone help?
Thanks,
Dan


Dim x, zz
Set objRoot = GetObject("LDAP://RootDSE";)
strDNC = objRoot.Get("DefaultNamingContext")

Set fso = CreateObject("Scripting.FileSystemObject")
Set txtstream = fso.CreateTextFile("\\server\c$\ad.txt", True)

arrOUs = Array("cn=microsoft exchange system objects,dc=domain,dc=com",
_
"ou=exchange,ou=enterprise servers,dc=domain,dc=com", _
"ou=exchange,ou=enterprise servers,dc=domain,dc=com")

For Each strOU In arrOUs
Set objOU = GetObject("LDAP://"; & strOU)
Call EnumMembers(objOU)
Next

Sub enumMembers(objOU)
On Error Resume Next
Dim Secondary(20) ' Variable to store the Array of 2ndary email alias's

For Each objMember In objOU ' go through the collection


' if not User object or if user has no mail enabled, move on.

If objMember.class = "publicFolder" _
Or objMember.class = "user" _
Or objMember.class = "group" Then
If objMember.proxyAddresses <> "" Then
IF NOT ((objMember.userAccountControl AND 2) = 2) Then
IF objmember.extensionattribute1 <> "Exclude" Then


' I set AD properties to variables so if needed you could do Null
checks or add if/then's to this code. This was done so the script
could be modified easier.

EmailAddr = objMember.mail

zz = 1 ' Counter for array of 2ndary email addresses
For each email in ObjMember.proxyAddresses
If Left (email,5) = "SMTP:" Then
Primary = Mid (email,6) ' if SMTP is all caps, then it's the Primary
ElseIf Left (email,5) = "smtp:" Then
Secondary(zz) = Mid (email,6) ' load the list of 2ndary SMTP
emails into Array.
zz = zz + 1
End If
Next

txtstream.write Primary & ", "

' Write out the Array for the 2ndary email addresses.
For ll = 1 To 20

txtstream.write Secondary(ll) & ", "


Next
' Blank out Variables in case the next object doesn't have a value for
the property

Primary = "-"
For ll = 1 To 20
Secondary(ll) = ""
Next
End If
End If
End If
End If

' If the AD enumeration runs into an OU object, call the Sub again to
itinerate

If objMember.Class = "organizationalUnit" or OBjMember.Class =
"container" Then
enumMembers (objMember)
End If


Next
End Sub

'This code takes out all blank lines in the output of the results file.

txtstream.close

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("\\server\c$\ad.txt", ForReading)

Do Until objFile.AtEndOfStream
strLine = objFile.Readline
strLine = Trim(strLine)
If Len(strLine) > 0 Then
strNewContents = strNewContents & strLine & vbCrLf
End If
Loop

objFile.Close

Set objFile = objFSO.OpenTextFile("\\server\c$\ad.txt", ForWriting)
objFile.Write strNewContents
objFile.Close

MsgBox "Done" ' show that script is complete




.



Relevant Pages

  • Re: Formatting...
    ... and puts a comma there to show separation. ... "if" statement to search that array and not write it. ... something like if EmailAddr or whatever your using ... Now when I run the script the output is like this: ...
    (microsoft.public.scripting.vbscript)
  • Re: How to just grab email addresses?
    ... and export them into a text doc separated only by a comma. ... To get ONLY the default email address, you'd have to do it by script: ... set end of eAddresses to default email address of theContact ... set AppleScript's text item delimiters to ...
    (microsoft.public.mac.office.entourage)
  • Re: ORS Flush problem??
    ... I think you probably meant to set OFS above, ... In the above script, I am double qouting my sixth field and then ... trying to print all the fields separated by comma. ... Then don't mess with the ORS as that what it is by default. ...
    (comp.lang.awk)
  • Re: Tony Coopers downhill slide
    ... >zeroed in on the undesirable interruption the first comma ... >to understand what the purpose of the comma was and probably ... >remark being punctuated as parenthetical. ... parenthetical phrase out of something that need not - even should not ...
    (alt.usage.english)
  • Flush problem
    ... In the above script, I am double qouting my sixth field and then ... trying to print all the fields separated by comma. ... So I tried introducing print stmt which is the last commented stmt in ... FAILED, STREAM SMKTIS_TPEMGR03G, NO RECOVERY SPECIFIED",P3, ...
    (comp.lang.awk)