mikeleahy
asked on
email script
hi there
im using hte following script to get list of all email addresses and getting a line 100 , char 37 error - illegal character. can you someone help me?
'========================= ========== ========== ========== ========== ========== ========== ========== ===
'
' VBScript Source File
'
' NAME: LISTPROXYADDRESSES.VBS
' VERSION: 0.9
' AUTHOR: Bharat Suneja , Bharat Suneja
' CREATE DATE : 5/06/2004
' LAST MODIFIED : 9/23/2005
'========================= ========== ========== ========== ========== ========== ========== ========== ===
' COMMENT:
'
'========================= ========== ========== ========== ========== ========== ========== ========== ===
'Set up constant for deleting values from multivalued attribute memberOf
Const ADS_PROPERTY_NOT_FOUND = &h8000500D
Const ADS_UF_ACCOUNTDISABLE = 2 'For UserAccountControl
Const strX400Search = "X400"
'_________________________ __________ __________ _________
'Set RootDSE
Set objRootDSE = GetObject("LDAP://rootDSE" )
strDomain = objRootDSE.Get("defaultNam ingContext ")
strADPath = "LDAP://" & strDomain
'wscript.Echo strADPath
Set objDomain = GetObject(strADPath)
'wscript.echo "objDomain: " & objDomain.distinguishedNam e
'Setup ADODB connection
Set objConnection = CreateObject("ADODB.Connec tion")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Comman d")
objCommand.ActiveConnectio n = objConnection
'Execute search command to look for Contacts & Groups
objCommand.CommandText = _
"<" & strADPath & ">" & ";(&(|(objectClass=contact )(objectCl ass=group) )(mail=*)) " & ";distinguishedName,displa yName,mail ,proxyAddr esses;subt ree"
'Execute search to get Recordset
Set objRecordSet = objCommand.Execute
'Start procedure
strResult = strResult & VbCrLf & "Domain: " & strDomain
strResult = strResult & VbCrlf & "#Total Records Found (other accounts): " & objRecordSet.RecordCount & VbCrlf
AddressCount = 0
While Not objRecordSet.EOF 'Iterate through the search results
strUserDN = objRecordSet.Fields("disti nguishedNa me") 'Get User's distinguished name from Recordset into a string
set objUser= GetObject("LDAP://"& strUserDN & "") 'Use string to bind to user object
strResult = strResult & VbCrlf & "cn: " & objUser.cn
strResult = strResult & VbCrlf & "mail: " & objUser.mail
arrProxyAddresses = objRecordSet.Fields("proxy Addresses" )
If IsArray(objRecordSet.Field s("proxyAd dresses")) Then
strResult = strResult & VbCrLf & "Proxy Addresses"
For Each ProxyAddress in arrProxyAddresses
'Sub: Check X400
If InStr(ProxyAddress, strX400Search) <> 0 Then
'Wscript.Echo "#This was an x400"
Else
strResult = strResult & VbCrlf & proxyAddress
End If 'Ends loop for X400 address
Next
Else
strResult = strResult & VbCrlf & "#Object does not have proxy addresses"
End If
strResult = strResult & VbCrLf
objRecordSet.MoveNext
Wend
'************************* ********** **
'Begin second query for users
varDisabledCounter = 0
'Execute search command to look for user
objCommand.CommandText = _
"<" & strADPath & ">" & ";(&(objectClass=user)(mai l=*))" & ";distinguishedName,displa yName,mail ,proxyAddr esses;subt ree"
'Execute search to get Recordset
Set objRecordSet = objCommand.Execute
strResult = strResult & vbCrlf & "#Users"
strResult = strResult & VbCrlf & "#Total Records Found (users): " & objRecordSet.RecordCount & VbCrlf
While Not objRecordSet.EOF 'Iterate through the search results
strUserDN = objRecordSet.Fields("disti nguishedNa me") 'Get User's distinguished name from Recordset into a string
strUserDN = Replace(strUserDN, “/”, “\/”)
set objUser= GetObject("LDAP://"& strUserDN & "") 'Use string to bind to user object
If objUser.AccountDisabled = TRUE Then 'If User account disabled, then skip proxy address enum
varDisabledCounter = varDisabledCounter + 1
strResult2 = strResult2 & VbCrLf & varDisabledCounter & " " & objUser.displayName & VbCrLf
strResult2 = strResult2 & "cn: " & objUser.cn
strResult2 = strResult2 & VbCrlf & "mail: " & objUser.mail
arrProxyAddresses = objRecordSet.Fields("proxy Addresses" )
If IsArray(objRecordSet.Field s("proxyAd dresses")) Then
strResult2 = strResult2 & VbCrLf & "Proxy Addresses"
For Each ProxyAddress in arrProxyAddresses
'Sub: Check X400
If InStr(ProxyAddress, strX400Search) <> 0 Then
'Wscript.Echo "#This was an x400"
Else
strResult2 = strResult2 & VbCrlf & proxyAddress
AddressCount = AddressCount + 1
End If 'Ends loop for X400 address
Next
Else
strResult2 = strResult2 & VbCrLf & "#Object does not have proxy addresses"
End If
strResult2 = strResult2 & VbCrLf
Else
strResult = strResult & VbCrlf & "cn: " & objUser.cn
strResult = strResult & VbCrlf & "mail: " & objUser.mail
arrProxyAddresses = objRecordSet.Fields("proxy Addresses" )
If IsArray(objRecordSet.Field s("proxyAd dresses")) Then
strResult = strResult & VbCrLf & "Proxy Addresses"
For Each ProxyAddress in arrProxyAddresses
'Sub: Check X400
If InStr(ProxyAddress, strX400Search) <> 0 Then
'Wscript.Echo "#This was an x400"
Else
strResult = strResult & VbCrlf & proxyAddress
AddressCount = AddressCount + 1
End If 'Ends loop for X400 address
Next
Else
strResult = strResult & VbCrLf & "#Object does not have proxy addresses"
End If
strResult = strResult & VbCrLf
End If 'End check for disabled user
objRecordSet.MoveNext
Wend 'End second query for users
strResult = "Users, Groups & Contacts" & VbCrLf & "------------------------- " & VbCrLf & strResult
strResult = strResult & VbCrLf & "Disabled Users" & VbCrLf & "------------------------- " & VbCrLf & strResult2
WScript.Echo strResult
'Output to a text file
Set objFileSystem = CreateObject("Scripting.Fi leSystemOb ject")
Set objOutputFile = objFileSystem.CreateTextFi le("C:\pro xyaddresse s.txt")
objOutputFile.Write strResult
im using hte following script to get list of all email addresses and getting a line 100 , char 37 error - illegal character. can you someone help me?
'=========================
'
' VBScript Source File
'
' NAME: LISTPROXYADDRESSES.VBS
' VERSION: 0.9
' AUTHOR: Bharat Suneja , Bharat Suneja
' CREATE DATE : 5/06/2004
' LAST MODIFIED : 9/23/2005
'=========================
' COMMENT:
'
'=========================
'Set up constant for deleting values from multivalued attribute memberOf
Const ADS_PROPERTY_NOT_FOUND = &h8000500D
Const ADS_UF_ACCOUNTDISABLE = 2 'For UserAccountControl
Const strX400Search = "X400"
'_________________________
'Set RootDSE
Set objRootDSE = GetObject("LDAP://rootDSE"
strDomain = objRootDSE.Get("defaultNam
strADPath = "LDAP://" & strDomain
'wscript.Echo strADPath
Set objDomain = GetObject(strADPath)
'wscript.echo "objDomain: " & objDomain.distinguishedNam
'Setup ADODB connection
Set objConnection = CreateObject("ADODB.Connec
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Comman
objCommand.ActiveConnectio
'Execute search command to look for Contacts & Groups
objCommand.CommandText = _
"<" & strADPath & ">" & ";(&(|(objectClass=contact
'Execute search to get Recordset
Set objRecordSet = objCommand.Execute
'Start procedure
strResult = strResult & VbCrLf & "Domain: " & strDomain
strResult = strResult & VbCrlf & "#Total Records Found (other accounts): " & objRecordSet.RecordCount & VbCrlf
AddressCount = 0
While Not objRecordSet.EOF 'Iterate through the search results
strUserDN = objRecordSet.Fields("disti
set objUser= GetObject("LDAP://"& strUserDN & "") 'Use string to bind to user object
strResult = strResult & VbCrlf & "cn: " & objUser.cn
strResult = strResult & VbCrlf & "mail: " & objUser.mail
arrProxyAddresses = objRecordSet.Fields("proxy
If IsArray(objRecordSet.Field
strResult = strResult & VbCrLf & "Proxy Addresses"
For Each ProxyAddress in arrProxyAddresses
'Sub: Check X400
If InStr(ProxyAddress, strX400Search) <> 0 Then
'Wscript.Echo "#This was an x400"
Else
strResult = strResult & VbCrlf & proxyAddress
End If 'Ends loop for X400 address
Next
Else
strResult = strResult & VbCrlf & "#Object does not have proxy addresses"
End If
strResult = strResult & VbCrLf
objRecordSet.MoveNext
Wend
'*************************
'Begin second query for users
varDisabledCounter = 0
'Execute search command to look for user
objCommand.CommandText = _
"<" & strADPath & ">" & ";(&(objectClass=user)(mai
'Execute search to get Recordset
Set objRecordSet = objCommand.Execute
strResult = strResult & vbCrlf & "#Users"
strResult = strResult & VbCrlf & "#Total Records Found (users): " & objRecordSet.RecordCount & VbCrlf
While Not objRecordSet.EOF 'Iterate through the search results
strUserDN = objRecordSet.Fields("disti
strUserDN = Replace(strUserDN, “/”, “\/”)
set objUser= GetObject("LDAP://"& strUserDN & "") 'Use string to bind to user object
If objUser.AccountDisabled = TRUE Then 'If User account disabled, then skip proxy address enum
varDisabledCounter = varDisabledCounter + 1
strResult2 = strResult2 & VbCrLf & varDisabledCounter & " " & objUser.displayName & VbCrLf
strResult2 = strResult2 & "cn: " & objUser.cn
strResult2 = strResult2 & VbCrlf & "mail: " & objUser.mail
arrProxyAddresses = objRecordSet.Fields("proxy
If IsArray(objRecordSet.Field
strResult2 = strResult2 & VbCrLf & "Proxy Addresses"
For Each ProxyAddress in arrProxyAddresses
'Sub: Check X400
If InStr(ProxyAddress, strX400Search) <> 0 Then
'Wscript.Echo "#This was an x400"
Else
strResult2 = strResult2 & VbCrlf & proxyAddress
AddressCount = AddressCount + 1
End If 'Ends loop for X400 address
Next
Else
strResult2 = strResult2 & VbCrLf & "#Object does not have proxy addresses"
End If
strResult2 = strResult2 & VbCrLf
Else
strResult = strResult & VbCrlf & "cn: " & objUser.cn
strResult = strResult & VbCrlf & "mail: " & objUser.mail
arrProxyAddresses = objRecordSet.Fields("proxy
If IsArray(objRecordSet.Field
strResult = strResult & VbCrLf & "Proxy Addresses"
For Each ProxyAddress in arrProxyAddresses
'Sub: Check X400
If InStr(ProxyAddress, strX400Search) <> 0 Then
'Wscript.Echo "#This was an x400"
Else
strResult = strResult & VbCrlf & proxyAddress
AddressCount = AddressCount + 1
End If 'Ends loop for X400 address
Next
Else
strResult = strResult & VbCrLf & "#Object does not have proxy addresses"
End If
strResult = strResult & VbCrLf
End If 'End check for disabled user
objRecordSet.MoveNext
Wend 'End second query for users
strResult = "Users, Groups & Contacts" & VbCrLf & "-------------------------
strResult = strResult & VbCrLf & "Disabled Users" & VbCrLf & "-------------------------
WScript.Echo strResult
'Output to a text file
Set objFileSystem = CreateObject("Scripting.Fi
Set objOutputFile = objFileSystem.CreateTextFi
objOutputFile.Write strResult
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER