Item Attachments in EWS allow you to create an Attachment that is of a Rich Exchange type such as an EmailMessage, Task, Post, Contact etc or even your own custom form if your using these. Although one thing you can't do with an Item attachment is attach an existing Exchange Item.
To use ItemAttachments in Powershell you need to use reflection in .NET as it involves invoking a Generic Method which is not that straight forward in Powershell.
The following is an example of creating a Task as an Item Attachment in Powershell using reflection
To use ItemAttachments in Powershell you need to use reflection in .NET as it involves invoking a Generic Method which is not that straight forward in Powershell.
The following is an example of creating a Task as an Item Attachment in Powershell using reflection
- $mail = New-Object Microsoft.Exchange.WebServices.Data.EmailMessage($service);
- $AtColtype = ("Microsoft.Exchange.WebServices.Data.AttachmentCollection") -as "Type"
- $Tasktype = ("Microsoft.Exchange.WebServices.Data.Task") -as "Type"
- $methodInf = $AtColtype.GetMethod("AddItemAttachment");
- $AddItmAttachMethod = $methodInf.MakeGenericMethod($Tasktype);
- $TaskAttachment = $AddItmAttachMethod.Invoke($mail.Attachments,$null);
- $TaskAttachment.Item.Subject = "Mondays Task"
- $TaskAttachment.Item.StartDate = (Get-Date)
- $TaskAttachment.Item.DueDate = (Get-Date).AddDays(7)
- $TaskAttachment.Name = "Mondays Task"
- $mail.Subject = "See the Attached Task"
- $mail.ToRecipients.Add("user@domain.com")
- $mail.SendAndSaveCopy()