Re: Formatting...
- From: "Its me Earnest T." <spam@xxxxxxxxxxxxxxxxxx>
- Date: Wed, 25 Oct 2006 23:47:04 GMT
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
.
- Follow-Ups:
- Re: Formatting...
- From: dankennedy24
- Re: Formatting...
- References:
- Formatting...
- From: dankennedy24
- Re: Formatting...
- From: Its me Earnest T.
- Re: Formatting...
- From: dankennedy24
- Formatting...
- Prev by Date: Re: Passing the resulting variable to a file
- Next by Date: Re: Formatting...
- Previous by thread: Re: Formatting...
- Next by thread: Re: Formatting...
- Index(es):
Relevant Pages
|