Skip to main content

Displaying the Junk-Email setting of all users on a Server (Exchange 2003)

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

Popular posts from this blog

Export calendar Items to a CSV file using EWS and Powershell

Somebody asked about this last week and while I have a lot of EWS scripts that do access the Calendar I didn't have a simple example that just exported a list of the Calendar events with relevant information to a CSV file so here it is.

I've talked on this one before in this howto  but when you query the calendar folder using EWS you need to use a CalendarView which will expand any recurring appointments in a calendar. There are some limits when you use a calendarview in that you can only return a maximum of 2 years of appointments at a time and paging will limit the max number of items to 1000 per call. So if you have a calendar with a very large number of appointments you need to break your query into small date time blocks. In this example script I'm just grabbing the next 7 days of appointments if you want to query a longer period you need to adjust the following lines (keeping in mind what I just mentioned)

#Define Date to Query
$StartDate = (Get-Date)
$EndDate = (Ge…

EWS Managed API and Powershell How-To series Part 1

I thought I'd start the year with a series of posts that goes back over the basics of using the EWS Managed API from Powershell and provides a modular remarked example that you can easily cut and paste to build your own scripts. Along the way in this series I'll show a whole bunch of examples around specific things.

As a starting point for versions this will be Powershell Version 2.0  and the EWS Managed API 1.1 (which will soon change to 1.2 once released) http://www.microsoft.com/download/en/details.aspx?id=13480.

The starting point for any EWS script your going to write is connecting to Exchange for which there are three important pieces of information you will need. Firstly you need to know the version of Exchange your running in this script its going to be held in the following variable

$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1

Other valid values for Exchange 2007 would be

$ExchangeVersion = [Microsoft.Exchange.WebServices.…

Writing a simple scripted process to download attachmentts in Exchange 2007/ 2010 using the EWS Managed API

Every complicated thing in life is made up of smaller simpler building blocks, when it comes to writing a script (or any code really) the more of these little building blocks you have to figure out the more the process of solving a problem can become bewildering. The Internet generally provides you with lots of half eaten sandwiches of information something someone else has taken a bite out but a lot of the time half done, and as with any code its usefulness declines over time as new and better API's and methods are derived. In this post I'm going to go through a simple scripted process that hopefully covers a few more of these smaller building blocks that you might face when asked to come up with a simple costless solution to perform an automated business function with a script.

So the process im going to look at is one that comes up a lot and that is you have an Email that comes into to certain mailbox every day with a certain subject in my case "Daily Export" this …
All sample scripts and source code is provided by for illustrative purposes only. All examples are untested in different environments and therefore, I cannot guarantee or imply reliability, serviceability, or function of these programs.

All code contained herein is provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.