Re: Formatting...



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...
    ... EmailAddr = objMember.mail & vbcrlf ... depending on where the commas are ... I have the following script which outputs a user's primary email ...
    (microsoft.public.scripting.vbscript)
  • Re: MsgBox help needed
    ... was attacking it in the wrong area of the script. ... displaycount = displaycount + 1 ... intNoOfValidPicks = intNoOfValidPicks + 1 ... vbCrLf & vbCrLf & vbCrLf ...
    (microsoft.public.scripting.vbscript)
  • Re: Program to get hardware info?
    ... I found this nice little vbs script that does almost what I want. ... <Inventories computer configuration and writes report to ... report = report & vbCrLf & ... that, I think, lists all available info for the various classes for the one ...
    (microsoft.public.scripting.vbscript)
  • Re: Help Me Fix Script
    ... Months ago I used the following vbs script to extract all the ID3 tags ... : ts.write FLDR.self.path & vbcrlf ... wscript.echo "You must include the full path to a folder as an argument" ...
    (microsoft.public.scripting.vbscript)
  • Re: Deleting log files
    ... get the script to work properly when I am attempting to test them. ... & vbcrlf & vbcrlf ... Set ObjFile = ObjFS.GetFile ... Set oFSFile = oFS.OpenTextFile(strObjTopFolderPath & ...
    (microsoft.public.scripting.vbscript)