by

Dumping out the MailTips for all of the recipients utilizing EWS and Powershell

Dumping out the MailTips for all of the recipients utilizing EWS and Powershell MailTip’s are a function in Alternate from 2010 that provides you additional data when sending a message. In a pervious put up I confirmed how you need to use these to get the Outlook of Workplace standing for a consumer utilizing MailTips in EWS. On this Publish I’ve a pattern for going by means of and dumping out all of the MailTips for all of the Recipients in Alternate (which might be feed in utilizing Get-Recipient to incorporate Contacts, Distribution checklist and some other kind of recipeint) and produces an output like

 
 


As a result of there aren’t any lessons within the EWS Managed API to make use of MailTips so I am simply utilizing Uncooked SOAP to ship the MailTips request after which parse the XML end result that comes again. With MailTips you’ll be able to solely request a max of 100 outcomes at a time so there may be some code to separate the request up in batches of 100 if there are extra the 100 entries.

I’ve put a download of this script right here the script appears like

## Get the Mailbox to Entry from the first commandline argument

$MailboxName = $args[0]

$Script:rptCollection = @()


###CHECK FOR EWS MANAGED API, IF PRESENT IMPORT THE HIGHEST VERSION EWS DLL, ELSE EXIT
$EWSDLL = (($(Get-ItemProperty -ErrorAction SilentlyContinue -Path Registry::$(Get-ChildItem -ErrorAction SilentlyContinue -Path 'Registry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftExchangeWeb Companies'|Type-Object Identify -Descending| Choose-Object -First 1 -ExpandProperty Identify)).'Set up Listing') + "Microsoft.Exchange.WebServices.dll")
if (Check-Path $EWSDLL)
{
Import-Module $EWSDLL
}
else
{
"$(get-date -format yyyyMMddHHmmss):"
"This script requires the EWS Managed API 1.2 or later."
"Please download and install the current version of the EWS Managed API from"
"http://go.microsoft.com/fwlink/?LinkId=255472"
""
"Exiting Script."
exit
}

## Set Alternate Model
$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Alternate2013_SP1

## Create Alternate Service Object
$service = New-Object Microsoft.Alternate.WebServices.Knowledge.ExchangeService($ExchangeVersion)

## Set Credentials to make use of two choices are availible Option1 to make use of explict credentials or Choice 2 use the Default (logged On) credentials

#Credentials Choice 1 utilizing UPN for the home windows Account
$psCred = Get-Credential
$creds = New-Object System.Internet.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())
$service.Credentials = $creds

#Credentials Choice 2
#service.UseDefaultCredentials = $true

## Select to disregard any SSL Warning points brought on by Self Signed Certificates

## Code From http://poshcode.org/624
## Create a compilation setting
$Supplier=New-Object Microsoft.CSharp.CSharpCodeProvider
$Compiler=$Supplier.CreateCompiler()
$Params=New-Object System.CodeDom.Compiler.CompilerParameters
$Params.GenerateExecutable=$False
$Params.GenerateInMemory=$True
$Params.IncludeDebugInformation=$False
$Params.ReferencedAssemblies.Add("System.DLL") | Out-Null

$TASource=@'
namespace Native.ToolkitExtensions.Internet.CertificatePolicy{
public class TrustAll : System.Internet.ICertificatePolicy {
public TrustAll() {
}
public bool CheckValidationResult(System.Internet.ServicePoint sp,
System.Safety.Cryptography.X509Certificates.X509Certificates cert,
System.Internet.WebRequest req, int drawback) {
return true;
}
}
}
'@
$TAResults=$Supplier.CompileAssemblyFromSource($Params,$TASource)
$TAAssembly=$TAResults.CompiledAssembly

## We now create an occasion of the TrustAll and fasten it to the ServicePointManager
$TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
[System.Internet.ServicePointManager]::CertificatePolicy=$TrustAll

## finish code from http://poshcode.org/624

## Set the URL of the CAS (Consumer Entry Server) to make use of two choices are availbe to make use of Autodiscover to seek out the CAS URL or Hardcode the CAS to make use of

#CAS URL Choice 1 Autodiscover
$service.AutodiscoverUrl($MailboxName,{$true})
"Using CAS Server : " + $Service.url

operate DumpMailTips{
param (
$Mailboxes = "$( throw 'Folder Path is a mandatory Parameter' )"
)
course of{

$expRequest = @"
<?xml model="1.0" encoding="utf-8"?>
<cleaning soap:Envelope xmlns:cleaning soap="http://schemas.xmlsoap.org/cleaning soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<cleaning soap:Header><RequestServerVersion Model="Alternate2010_SP1" xmlns="http://schemas.microsoft.com/alternate/providers/2006/varieties" />
</cleaning soap:Header>
<cleaning soap:Physique>
<GetMailTips xmlns="http://schemas.microsoft.com/alternate/providers/2006/messages">
<SendingAs>
<EmailAddress xmlns="http://schemas.microsoft.com/alternate/providers/2006/varieties">$MailboxName</EmailAddress>
</SendingAs>
<Recipients>
"@

foreach($mbMailbox in $Mailboxes){
$expRequest = $expRequest + "<Mailbox xmlns=`"http://schemas.microsoft.com/alternate/providers/2006/varieties`"><EmailAddress>$mbMailbox</EmailAddress></Mailbox>"
}

$expRequest = $expRequest + "</Recipients><MailTipsRequested>All</MailTipsRequested></GetMailTips></soap:Body></soap:Envelope>"
$mbMailboxFolderURI = New-Object System.Uri($service.url)
$wrWebRequest = [System.Internet.WebRequest]::Create($mbMailboxFolderURI)
$wrWebRequest.KeepAlive = $false;
$wrWebRequest.Headers.Set("Pragma", "no-cache");
$wrWebRequest.Headers.Set("Translate", "f");
$wrWebRequest.Headers.Set("Depth", "0");
$wrWebRequest.ContentType = "text/xml";
$wrWebRequest.ContentLength = $expRequest.Size;
$wrWebRequest.CookieContainer = New-Object System.Internet.CookieContainer
$wrWebRequest.Timeout = 60000;
$wrWebRequest.Technique = "POST";
$wrWebRequest.Credentials = $creds
$bqByteQuery = [System.Textual content.Encoding]::ASCII.GetBytes($expRequest);
$wrWebRequest.ContentLength = $bqByteQuery.Size;
$rsRequestStream = $wrWebRequest.GetRequestStream();
$rsRequestStream.Write($bqByteQuery, 0, $bqByteQuery.Size);
$rsRequestStream.Shut();
$wrWebResponse = $wrWebRequest.GetResponse();
$rsResponseStream = $wrWebResponse.GetResponseStream()
$sr = new-object System.IO.StreamReader($rsResponseStream);
$rdResponseDocument = New-Object System.Xml.XmlDocument
$rdResponseDocument = New-Object System.Xml.XmlDocument
$rdResponseDocument.LoadXml($sr.ReadToEnd());
$Datanodes = @($rdResponseDocument.getElementsByTagName("m:MailTips"))

foreach($nodeVal in $Datanodes) Choose RecipientAddress,RecipientTypeDetails,PendingMailTips,OutOfOffice,CustomMailTip,MailboxFull,TotalMemberCount,ExternalMemberCount,MaxMessageSize,DeliveryRestricted,IsModerated
$rptObj.RecipientAddress = $nodeVal.RecipientAddress.EmailAddress
$rptObj.RecipientTypeDetails = $Script:emAray[$rptObj.RecipientAddress.ToLower()]
$rptObj.PendingMailTips = $nodeVal.PendingMailTips."#text"
$rptObj.OutOfOffice = $nodeVal.OutOfOffice.ReplyBody.Message
$rptObj.CustomMailTip = $nodeVal.CustomMailTip."#text"
$rptObj.MailboxFull = $nodeVal.MailboxFull."#text"
$rptObj.TotalMemberCount = $nodeVal.TotalMemberCount."#text"
$rptObj.ExternalMemberCount = $nodeVal.ExternalMemberCount."#text"
$rptObj.MaxMessageSize = $nodeVal.MaxMessageSize."#text"
$rptObj.DeliveryRestricted = $nodeVal.DeliveryRestricted."#text"
$rptObj.IsModerated = $nodeVal.IsModerated."#text"
$Script:rptCollection += $rptObj


}
}
$mbscn = @()
$Script:emAray = @{}
$rcps = Get-Recipient -ResultSize Limitless
$rcps | ForEach-Object {
$Script:emAray.Add($_.PrimarySMTPAddress.ToString().ToLower(),$_.RecipientTypeDetails)
$mbscn += $_.PrimarySMTPAddress.ToString()
if($mbscn.rely -gt 100){
dumpmailtips -Mailboxes $mbscn
$mbscn = @()
}
}
if($mbscn.rely -gt 0){
dumpmailtips -Mailboxes $mbscn
}
$Script:rptCollection | Export-Csv -Path c:tempMailTipsDump.csv -NoTypeInformation