I got a good question this week about one of my previous posts about displaying and setting junk Email setting on Exchange 2003. What this person wanted to do was display the junkemail setting of all users on a server so they could see who had enabled junk email filtering in OWA. This was a good idea which I thought could be expended a little further an also include reporting on the junk email settings from Outlook 2003 as well. So what I’ve done is put together a script that creates a CSV file that shows you firstly weather the Extended Junk Email rule has been created in a mailbox, If junk email filtering is enabled in OWA, what level junk email filter has been set to in Outlook 2003 and what the delete setting is set to in Outlook 2003. What you end up with is a pretty useful little report on how people are using the Junk Email filtering setting in Outlook and OWA on your server.
I’ve created two versions of the script the first is a WebDAV version which can be run locally or remotely and I’ve also done a Exoledb version that must be run locally on the server. Both scripts work the same way they do a search of the inbox folder for the extended junk email rule by searching for IPM.ExtendedRule.Message items that are named JunkEmailRule. The existence of this rules mean someone has either turned on junk email filtering in OWA or connected to the mailbox with Outlook 2003. To see what the current junk-email filtering setting are you need to check properties on the rule object itself. Checking the PR_Rulemsgstate http://schemas.microsoft.com/mapi/proptag/x65E90003 property will tell you weather someone has disabled this rule via OWA if the value is 48 then the check box will be un-ticked in OWA. The other two setting I’ve mentioned before.
http://schemas.microsoft.com/mapi/proptag/0x61010003 which stores a long value that sets that level of junk email protection you want the long values for each of the setting are
No Automatic filtering = -1
Low = 6
High = 3
Safe Lists only = -2147483648
The “Permanently delete suspected junk e-mail instead of moving it to the Junk E-mail folder” is stored in the http://schemas.microsoft.com/mapi/proptag/0x61020003 as
Disabled = 0
Enabled = 1
The script reports the result to a csv file on the c drive called junkemailsettings.csv
To run the scripts for the WebDAV version it uses the Exadmin virtual directory so you need to include the servername you want to run it against and also your default domain name (you can find this by checking the properties of the exadmin virtual directory in IIS admin). Eg cscript showjmailopsdav1.vbs servername domain.com
To run the exoledb version you just need the servername as command line parameters. Both scripts require that you run them with an account that has rights to every users mailbox
I’ve put a downloadable copy of the script here the webdav version look like
servername = wscript.arguments(0)
domainname = wscript.arguments(1)
Set fso = CreateObject("Scripting.FileSystemObject")
set wfile = fso.opentextfile("c:\Junkemailsettings.csv",2,true)
wfile.writeline("Mailbox,OWAJunkEmailState,Outlook Filter Setting,Outlook Delete
Junk Email Setting")
set conn = createobject("ADODB.Connection")
set com = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
strNameingContext = iAdRootDSE.Get("configurationNamingContext")
strDefaultNamingContext = iAdRootDSE.Get("defaultNamingContext")
Conn.Provider = "ADsDSOObject"
Conn.Open "ADs Provider"
svcQuery = "<LDAP://" & strNameingContext & ">;(&(objectCategory=msExchExchangeServer)(cn="
& Servername & "));cn,name,legacyExchangeDN;subtree"
Com.ActiveConnection = Conn
Com.CommandText = svcQuery
Set Rs = Com.Execute
while not rs.eof
GALQueryFilter = "(&(&(&(& (mailnickname=*)(!msExchHideFromAddressLists=TRUE)(|
(&(objectCategory=person)(objectClass=user)(msExchHomeServerName=" &
rs.fields("legacyExchangeDN") & ")) )))))"
strQuery = "<LDAP://" & strDefaultNamingContext & ">;" & GALQueryFilter & ";distinguishedName,mail;subtree"
com.Properties("Page Size") = 100
Com.CommandText = strQuery
Set Rs1 = Com.Execute
while not Rs1.eof
call ProcMailbox(servername,rs1.fields("mail"))
rs1.movenext
wend
rs.movenext
wend
rs.close
wfile.close
set fso = nothing
set conn = nothing
set com = nothing
wscript.echo "Done"
Sub ProcMailbox(snServername,mnMailboxname)
wscript.echo "Processing : " & mnMailboxname
SourceURL = "http://" & snServername & "/exadmin/" & domainname & "/mbx/" &
mnMailboxname & "/inbox/"
strQuery = "<?xml version=""1.0""?><D:searchrequest xmlns:D = ""DAV:"" >"
strQuery = strQuery & "<D:sql>SELECT ""DAV:displayname"", ""http://schemas.microsoft.com/mapi/proptag/x65E90003"",
"
strQuery = strQuery & """http://schemas.microsoft.com/mapi/proptag/x61010003"",
""http://schemas.microsoft.com/mapi/proptag/x61020003"""
strQuery = strQuery & " FROM scope('shallow traversal of """
strQuery = strQuery & SourceURL & """') Where ""DAV:ishidden"" = True AND ""DAV:isfolder""
= False AND "
strQuery = strQuery & """http://schemas.microsoft.com/exchange/outlookmessageclass""
= 'IPM.ExtendedRule.Message' "
strQuery = strQuery & "AND ""http://schemas.microsoft.com/mapi/proptag/0x65EB001E""
= 'JunkEmailRule' </D:sql></D:searchrequest>"
set req = createobject("microsoft.xmlhttp")
req.open "SEARCH", SourceURL, false,"", ""
req.setrequestheader "Content-Type", "text/xml"
req.setRequestHeader "Translate","f"
req.send strQuery
wscript.echo "Status: " & req.status
wscript.echo "Status text: " & req.statustext
If req.status >= 500 Then
ElseIf req.status = 207 Then
set oResponseDoc = req.responseXML
set oNodeList = oResponseDoc.getElementsByTagName("a:href")
set ostateList = oResponseDoc.getElementsByTagName("d:x65E90003")
set ofilterList = oResponseDoc.getElementsByTagName("d:x61010003")
set odeleteList = oResponseDoc.getElementsByTagName("d:x61020003")
For i = 0 To (oNodeList.length -1)
set oNode = oNodeList.nextNode
Filterlist = ofilterList(i).nodetypedvalue
if filterlist = "" then
flist = "No Automatic filtering"
else
select case Filterlist
case -1 flist = "No Automatic filtering"
case 6 flist = "Low"
case 3 flist = "High"
case -2147483648 flist = "Safe Lists only"
end select
end if
delist = odeleteList(i).nodetypedvalue
if delist = "" then
delset = "Disabled"
else
select case delist
case 1 delset = "Enabled"
case 0 delset = "Disabled"
end select
end if
Rule_State = ostateList(i).nodetypedvalue
select case Rule_State
case 48 wfile.writeline(mnMailboxname & "," & "OWA Junk Email Setting Off," &
flist & "," & delset)
case 49 wfile.writeline(mnMailboxname & "," & "OWA Junk Email Setting Enabled,"
& flist & "," & delset)
end Select
Next
if oNodeList.length = 0 then
wfile.writeline(mnMailboxname & "," & "No Junk Email rules Exists")
End if
Else
End If
end sub
I’ve created two versions of the script the first is a WebDAV version which can be run locally or remotely and I’ve also done a Exoledb version that must be run locally on the server. Both scripts work the same way they do a search of the inbox folder for the extended junk email rule by searching for IPM.ExtendedRule.Message items that are named JunkEmailRule. The existence of this rules mean someone has either turned on junk email filtering in OWA or connected to the mailbox with Outlook 2003. To see what the current junk-email filtering setting are you need to check properties on the rule object itself. Checking the PR_Rulemsgstate http://schemas.microsoft.com/mapi/proptag/x65E90003 property will tell you weather someone has disabled this rule via OWA if the value is 48 then the check box will be un-ticked in OWA. The other two setting I’ve mentioned before.
http://schemas.microsoft.com/mapi/proptag/0x61010003 which stores a long value that sets that level of junk email protection you want the long values for each of the setting are
No Automatic filtering = -1
Low = 6
High = 3
Safe Lists only = -2147483648
The “Permanently delete suspected junk e-mail instead of moving it to the Junk E-mail folder” is stored in the http://schemas.microsoft.com/mapi/proptag/0x61020003 as
Disabled = 0
Enabled = 1
The script reports the result to a csv file on the c drive called junkemailsettings.csv
To run the scripts for the WebDAV version it uses the Exadmin virtual directory so you need to include the servername you want to run it against and also your default domain name (you can find this by checking the properties of the exadmin virtual directory in IIS admin). Eg cscript showjmailopsdav1.vbs servername domain.com
To run the exoledb version you just need the servername as command line parameters. Both scripts require that you run them with an account that has rights to every users mailbox
I’ve put a downloadable copy of the script here the webdav version look like
servername = wscript.arguments(0)
domainname = wscript.arguments(1)
Set fso = CreateObject("Scripting.FileSystemObject")
set wfile = fso.opentextfile("c:\Junkemailsettings.csv",2,true)
wfile.writeline("Mailbox,OWAJunkEmailState,Outlook Filter Setting,Outlook Delete
Junk Email Setting")
set conn = createobject("ADODB.Connection")
set com = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
strNameingContext = iAdRootDSE.Get("configurationNamingContext")
strDefaultNamingContext = iAdRootDSE.Get("defaultNamingContext")
Conn.Provider = "ADsDSOObject"
Conn.Open "ADs Provider"
svcQuery = "<LDAP://" & strNameingContext & ">;(&(objectCategory=msExchExchangeServer)(cn="
& Servername & "));cn,name,legacyExchangeDN;subtree"
Com.ActiveConnection = Conn
Com.CommandText = svcQuery
Set Rs = Com.Execute
while not rs.eof
GALQueryFilter = "(&(&(&(& (mailnickname=*)(!msExchHideFromAddressLists=TRUE)(|
(&(objectCategory=person)(objectClass=user)(msExchHomeServerName=" &
rs.fields("legacyExchangeDN") & ")) )))))"
strQuery = "<LDAP://" & strDefaultNamingContext & ">;" & GALQueryFilter & ";distinguishedName,mail;subtree"
com.Properties("Page Size") = 100
Com.CommandText = strQuery
Set Rs1 = Com.Execute
while not Rs1.eof
call ProcMailbox(servername,rs1.fields("mail"))
rs1.movenext
wend
rs.movenext
wend
rs.close
wfile.close
set fso = nothing
set conn = nothing
set com = nothing
wscript.echo "Done"
Sub ProcMailbox(snServername,mnMailboxname)
wscript.echo "Processing : " & mnMailboxname
SourceURL = "http://" & snServername & "/exadmin/" & domainname & "/mbx/" &
mnMailboxname & "/inbox/"
strQuery = "<?xml version=""1.0""?><D:searchrequest xmlns:D = ""DAV:"" >"
strQuery = strQuery & "<D:sql>SELECT ""DAV:displayname"", ""http://schemas.microsoft.com/mapi/proptag/x65E90003"",
"
strQuery = strQuery & """http://schemas.microsoft.com/mapi/proptag/x61010003"",
""http://schemas.microsoft.com/mapi/proptag/x61020003"""
strQuery = strQuery & " FROM scope('shallow traversal of """
strQuery = strQuery & SourceURL & """') Where ""DAV:ishidden"" = True AND ""DAV:isfolder""
= False AND "
strQuery = strQuery & """http://schemas.microsoft.com/exchange/outlookmessageclass""
= 'IPM.ExtendedRule.Message' "
strQuery = strQuery & "AND ""http://schemas.microsoft.com/mapi/proptag/0x65EB001E""
= 'JunkEmailRule' </D:sql></D:searchrequest>"
set req = createobject("microsoft.xmlhttp")
req.open "SEARCH", SourceURL, false,"", ""
req.setrequestheader "Content-Type", "text/xml"
req.setRequestHeader "Translate","f"
req.send strQuery
wscript.echo "Status: " & req.status
wscript.echo "Status text: " & req.statustext
If req.status >= 500 Then
ElseIf req.status = 207 Then
set oResponseDoc = req.responseXML
set oNodeList = oResponseDoc.getElementsByTagName("a:href")
set ostateList = oResponseDoc.getElementsByTagName("d:x65E90003")
set ofilterList = oResponseDoc.getElementsByTagName("d:x61010003")
set odeleteList = oResponseDoc.getElementsByTagName("d:x61020003")
For i = 0 To (oNodeList.length -1)
set oNode = oNodeList.nextNode
Filterlist = ofilterList(i).nodetypedvalue
if filterlist = "" then
flist = "No Automatic filtering"
else
select case Filterlist
case -1 flist = "No Automatic filtering"
case 6 flist = "Low"
case 3 flist = "High"
case -2147483648 flist = "Safe Lists only"
end select
end if
delist = odeleteList(i).nodetypedvalue
if delist = "" then
delset = "Disabled"
else
select case delist
case 1 delset = "Enabled"
case 0 delset = "Disabled"
end select
end if
Rule_State = ostateList(i).nodetypedvalue
select case Rule_State
case 48 wfile.writeline(mnMailboxname & "," & "OWA Junk Email Setting Off," &
flist & "," & delset)
case 49 wfile.writeline(mnMailboxname & "," & "OWA Junk Email Setting Enabled,"
& flist & "," & delset)
end Select
Next
if oNodeList.length = 0 then
wfile.writeline(mnMailboxname & "," & "No Junk Email rules Exists")
End if
Else
End If
end sub