I'm trying to script getting detailed information about the attachments to a calendar item with PowerShell and the EWS managed API. I've got this much so far:
$MailboxName = "<primarysmtpaddress>"
$dllpath = “C:\Program Files\Microsoft\Exchange\Web Services\1.0\Microsoft.Exchange.WebServices.dll”
[void][Reflection.Assembly]::LoadFile($dllpath)
$attPropset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.ItemSchema]::Attachments)
$fcPropset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)
$uri=[system.URI] “https://<CAS Server>/ews/exchange.asmx”
$service.Url = $uri
$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,$MailboxName)
$CalendarFolder = [Microsoft.Exchange.WebServices.Data.CalendarFolder]::Bind($service,$folderid)
$startdate = [System.DateTime]::Now.AddDays(-10)
$enddate = [System.DateTime]::Now.AddDays(10)
$Calendarview = new-object Microsoft.Exchange.WebServices.Data.CalendarView($startdate,$enddate)
$Calendarview.MaxItemsReturned = 100;
$Calendarview.PropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$CalendarResult = $CalendarFolder.FindAppointments($Calendarview)
$CalendarResult.Items.count
$hasatt = @($CalendarResult.Items |? {$_.HasAttachments})
$hasatt.count
$hasatt | select subject
if ($hasatt.Count -ge 1){
foreach ($attappt in $hasatt){
$appt_attrefs = [Microsoft.Exchange.WebServices.Data.Item]::Bind($service,$attappt.id,$attPropset)
foreach ($attref in $appt_attrefs.attachments){
$appt_attachment = [Microsoft.Exchange.WebServices.Data.Item]::Bind($service,$attref.id)
$appt_attachment
}
}
}
The only information I seem to be able to get about the attachment from the appointment is the subject line and ID. If I call the load() method that gets me the item type, but if I try to bind to that ID, I get "Exception calling "Bind" with "2" argument(s)" "Id is malformed"
If I check the ID, it's a string object that looks like:
AAMkAGRiYjMzNWFlLTMwN2YtNGUyOS1iZDc2LTYwYzkzNmIyMWU2MwBGAAAAAABZpmvEs/zSEZ0HQAAGUGDxBwApEJBBNPzSEYOC
QACZUGsBAAAAABgTAADDIw63zTGRRoA22NIjleYcAAF3ysShAAABEgAQAO29AXOr2H9Ou6bxVnJy688=
Anybody know what I'm doing wrong?