Junk Electronic mail SCL report utilizing EWS and Powershell

Junk Electronic mail SCL report utilizing EWS and Powershell Coping with Junk Electronic mail is form of like doing the dishes, it is soiled work however somebodies obtained to do it. Whereas Spam filters are enhancing we all know by the fixed updates these filters require its an invisible struggle that is at all times occurring. Additionally software program being what it’s, issues do not at all times go to plan like this http://assist.microsoft.com/kb/2885002/en-us

So it may be good to verify in on what’s occurring in your Person’s JunkEmail folders once in a while and EWS is nice for doing this so.

The next EWS script scans all of the messages within the JunkEmail folder of a Mailbox (or Mailboxes) and appears on the SCL worth of every of the Messages which is held within the

PidTagContentFilterSpamConfidenceLevel property

And likewise appears to be like on the

PidLidSpamOriginalFolder property which incorporates the unique folder a Message was moved from, which solely will get set when the Outlook Junk Electronic mail Filter takes an motion on a message vs the Server Facet motion (the place this properties does not get set)

This script produces a report that exhibits the variety of message for every SCL ranges, complete variety of messages within the JunkEmail folder and the variety of Messages transfer simply by simply Outlook Filter eg.

To run the script you want to feed it with a CSV with the mailbox you wish to run it in opposition to one thing like

SmtpAddress
[email protected]
[email protected]

Then use .sclReport.pst .customers.csv

I’ve put a download of the script right here

The script appears to be like like

  1. $Script:rptCollection = @()    
  2.   
  3. ## Load Managed API dll    
  4. Add-Sort -Path “C:Program FilesMicrosoftExchangeWeb Services2.0Microsoft.Exchange.WebServices.dll”    
  5.     
  6. ## Set Change Model    
  7. $ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Change2010_SP2    
  8.     
  9. ## Create Change Service Object    
  10. $service = New-Object Microsoft.Change.WebServices.Information.ExchangeService($ExchangeVersion)    
  11.     
  12. ## Set Credentials to use two choices are availible Option1 to use explict credentials or Choice 2 use the Default (logged On) credentials    
  13.     
  14. #Credentials Choice 1 utilizing UPN for the home windows Account    
  15. $psCred = Get-Credential    
  16. $creds = New-Object System.Internet.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())    
  17. $service.Credentials = $creds        
  18.     
  19. #Credentials Choice 2    
  20. #service.UseDefaultCredentials = $true    
  21.     
  22. ## Select to ignore any SSL Warning points triggered by Self Signed Certificates    
  23.     
  24. ## Code From http://poshcode.org/624  
  25. ## Create a compilation setting  
  26. $Supplier=New-Object Microsoft.CSharp.CSharpCodeProvider  
  27. $Compiler=$Supplier.CreateCompiler()  
  28. $Params=New-Object System.CodeDom.Compiler.CompilerParameters  
  29. $Params.GenerateExecutable=$False  
  30. $Params.GenerateInMemory=$True  
  31. $Params.IncludeDebugInformation=$False  
  32. $Params.ReferencedAssemblies.Add(“System.DLL”) | Out-Null  
  33.   
  34. $TASource[email protected] 
  35.   namespace Native.ToolkitExtensions.Internet.CertificatePolicy{ 
  36.     public class TrustAll : System.Internet.ICertificatePolicy { 
  37.       public TrustAll() {  
  38.       } 
  39.       public bool CheckValidationResult(System.Internet.ServicePoint sp, 
  40.         System.Safety.Cryptography.X509Certificates.X509Certificates cert,  
  41.         System.Internet.WebRequest req, int downside) { 
  42.         return true; 
  43.       } 
  44.     } 
  45.   } 
  46. @   
  47. $TAResults=$Supplier.CompileAssemblyFromSource($Params,$TASource)  
  48. $TAAssembly=$TAResults.CompiledAssembly  
  49.   
  50. ## We now create an occasion of the TrustAll and connect it to the ServicePointManager  
  51. $TrustAll=$TAAssembly.CreateInstance(“Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll”)  
  52. [System.Net.ServicePointManager]::CertificatePolicy=$TrustAll  
  53.   
  54. ## finish code from http://poshcode.org/624  
  55.     
  56. ## Set the URL of the CAS (Shopper Entry Server) to use two choices are availbe to use Autodiscover to discover the CAS URL or Hardcode the CAS to use    
  57.     
  58. #CAS URL Choice 2 Hardcoded    
  59.     
  60. #$uri=[system.URI] “https://casservername/ews/exchange.asmx”    
  61. #$service.Url = $uri      
  62.     
  63. ## Elective part for Change Impersonation    
  64.     
  65. #$service.ImpersonatedUserId = new-object Microsoft.Change.WebServices.Information.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $SmtpAddress)   
  66.   
  67. perform Course of-Mailbox{  
  68.     param (  
  69.             $SmtpAddress = “$( throw ‘SMTPAddress is a mandatory Parameter’ )”  
  70.           )  
  71.     course of{  
  72.         Write-Host (“Processing Mailbox : “ + $SmtpAddress)  
  73.         $rptObj = “” | choose MailboxName,TotalItems,MovedByOutlook,NoSCL,SCLneg1,SCL0,SCL1,SCL2,SCL3,SCL4,SCL5,SCL6,SCL7,SCL8,SCL9  
  74.         $rptObj.MovedByOutlook = 0  
  75.         $rptObj.NoSCL = 0  
  76.         $rptObj.SCLneg1 = 0  
  77.         $rptObj.SCL0 = 0  
  78.         $rptObj.SCL1 = 0  
  79.         $rptObj.SCL2 = 0  
  80.         $rptObj.SCL3 = 0  
  81.         $rptObj.SCL4 = 0  
  82.         $rptObj.SCL5 = 0  
  83.         $rptObj.SCL6 = 0  
  84.         $rptObj.SCL7 = 0  
  85.         $rptObj.SCL8 = 0  
  86.         $rptObj.SCL9 = 0  
  87.         # Bind to the Junk Electronic mail Folder  
  88.         $folderid= new-object Microsoft.Change.WebServices.Information.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::JunkEmail,$SmtpAddress)     
  89.         $JunkEmail = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)  
  90.         $rptObj.MailboxName = $SmtpAddress  
  91.         $rptObj.TotalItems = $JunkEmail.TotalCount  
  92.         $psPropset= new-object Microsoft.Change.WebServices.Information.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)  
  93.         $PidTagContentFilterSpamConfidenceLevel = new-object Microsoft.Change.WebServices.Information.ExtendedPropertyDefinition(0x4076, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer)  
  94.         $PidLidSpamOriginalFolder = new-object Microsoft.Change.WebServices.Information.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Frequent,0x859C, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary)  
  95.         $psPropset.Add($PidTagContentFilterSpamConfidenceLevel)  
  96.         $psPropset.Add($PidLidSpamOriginalFolder)  
  97.         #Outline ItemView to retrive simply 1000 Gadgets      
  98.         $ivItemView =  New-Object Microsoft.Change.WebServices.Information.ItemView(1000)    
  99.         $ivItemView.PropertySet = $psPropset  
  100.         $fiItems = $null      
  101.         do{      
  102.             $fiItems = $service.FindItems($JunkEmail.Id,$ivItemView)      
  103.             #[Void]$service.LoadPropertiesForItems($fiItems,$psPropset)    
  104.             foreach($Merchandise in $fiItems.Gadgets){  
  105.                 $OrigFldVal = $null  
  106.                 if($Merchandise.TryGetProperty($PidLidSpamOriginalFolder,[ref]$OrigFldVal)){  
  107.                     $rptObj.MovedByOutlook +=1  
  108.                 }  
  109.                 $SCLVal = $null;  
  110.                 if($Merchandise.TryGetProperty($PidTagContentFilterSpamConfidenceLevel,[ref]$SCLVal)){  
  111.                     change($SCLVal){  
  112.                         {$_ -lt 0}{$rptObj.SCLneg1 += 1}  
  113.                         0 { $rptObj.SCL0 += 1 }  
  114.                         1 { $rptObj.SCL1 += 1 }  
  115.                         2 { $rptObj.SCL2 += 1 }  
  116.                         3 { $rptObj.SCL3 += 1 }               
  117.                         4 { $rptObj.SCL4 += 1 }  
  118.                         5 { $rptObj.SCL5 += 1 }  
  119.                         6 { $rptObj.SCL6 += 1 }  
  120.                         7 { $rptObj.SCL7 += 1 }  
  121.                         8 { $rptObj.SCL8 += 1 }               
  122.                         9 { $rptObj.SCL9 += 1 }  
  123.                     }  
  124.                 }  
  125.                 else{  
  126.                     $rptObj.NoSCL +=1  
  127.                 }                          
  128.             }      
  129.             $ivItemView.Offset += $fiItems.Gadgets.Rely      
  130.         }whereas($fiItems.MoreAvailable -eq $true)   
  131.         $Script:rptCollection += $rptObj  
  132.     }  
  133. }  
  134.   
  135. Import-Csv -Path $args[0] | ForEach-Object{  
  136.     if($service.url -eq $null){  
  137.         $service.AutodiscoverUrl($_.SmtpAddress,{$true})   
  138.         “Using CAS Server : “ + $Service.url   
  139.     }  
  140.     Strive{  
  141.         Course of-Mailbox -SmtpAddress $_.SmtpAddress  
  142.     }  
  143.     catch{  
  144.         LogWrite(“Error processing Mailbox : “ + $_.SmtpAddress + $_.Exception.Message.ToString())  
  145.     }  
  146. }  
  147. $Script:rptCollection | Export-Csv -NoTypeInformation -Path c:tempsclReport.csv  

Leave a Reply