by

Utilizing the Birthday calendar in EWS in Trade 2016 and Workplace365

Utilizing the Birthday calendar in EWS in Trade 2016 and Workplace365 One of many new options that has been added in Trade 2016 and Workplace365 in OWA is a birthday calendar which is a devoted calendar for the Birthday appointments which might be related to contacts. eg

Like most of the particular folders in a Mailbox the folder identify for that is localized so in case your mailbox is ready to make use of a distinct language this folder identify ought to seem in your localized language. In contrast to a lot of the particular folders in Trade there isn’t any WellKnownFolder enumeration for the birthday calendar so if you wish to open this folder you both have to seek for it by identify (so long as you recognize the localization of the Mailbox) or you should use the next prolonged property that ought to exist on the basis mailbox folder.

So in EWS you are able to do one thing like the next to entry the HexEntryId worth from this prolonged property which you’ll be able to then convert to a EWSId utilizing the ConvertId operation after which it is possible for you to to bind to the folder utilizing that ID. eg

operate Get-BirthDayCalendar{
param (
[Parameter(Place=0, Obligatory=$true)] [string]$MailboxName,
[Parameter(Place=1, Obligatory=$true)] [System.Management.Automation.PSCredential]$Credentials,
[Parameter(Place=2, Obligatory=$false)] [switch]$useImpersonation )
course of{

$service = Join-Trade -MailboxName $MailboxName -Credentials $Credentials
if($useImpersonation.IsPresent){
$service.ImpersonatedUserId = new-object Microsoft.Trade.WebServices.Knowledge.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)
}
$folderid= new-object Microsoft.Trade.WebServices.Knowledge.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,$MailboxName)
$BirthdayCalendarFolderEntryId = New-Object Microsoft.Trade.WebServices.Knowledge.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Widespread,"BirthdayCalendarFolderEntryId",[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary);
$psPropset= new-object Microsoft.Trade.WebServices.Knowledge.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$psPropset.Add($BirthdayCalendarFolderEntryId)
$EWSRootFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid,$psPropset)
$BirthdayCalendarFolderEntryIdValue = $null
$BirthdayCalendarFolderHexValue = $null
if($EWSRootFolder.TryGetProperty($BirthdayCalendarFolderEntryId,[ref]$BirthdayCalendarFolderEntryIdValue)){
$BirthdayFolderEWSId = new-object Microsoft.Trade.WebServices.Knowledge.FolderId((ConvertId -HexId ([System.BitConverter]::ToString($BirthdayCalendarFolderEntryIdValue).Substitute("-",""))))
$BirthdayFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$BirthdayFolderEWSId);
return $BirthdayFolder
}
     else
{
throw [System.IO.FileNotFoundException] "folder not found."
}
}
}


Enumerating by means of birthdays and understanding a persons’ age :

Birthdays are saved as recurring appointments (as they do happen yearly) so if you wish to show all of the birthdays in a calendar its higher to make use of a CalendarView to develop any recurring appointments. To find out the Age of the particular person related to the calendar appointment you should use the Birthdaylocal property which holds the precise date of beginning (if it was entered). eg

Should you then do a Time distinction between that and the Begin time of the appointment that provides you with the Age of the particular person in days which you’ll be able to then convert to years utilizing some basic math. In code this seems like

operate Get-Birthdays{
param (
[Parameter(Place=0, Obligatory=$true)] [string]$MailboxName,
[Parameter(Place=1, Obligatory=$true)] [System.Management.Automation.PSCredential]$Credentials,
[Parameter(Place=2, Obligatory=$false)] [switch]$useImpersonation )
course of{

$service = Join-Trade -MailboxName $MailboxName -Credentials $Credentials
if($useImpersonation.IsPresent){
$service.ImpersonatedUserId = new-object Microsoft.Trade.WebServices.Knowledge.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)
}
$strtime = (Get-date).12 months.ToString() + "0101"
$endtime = (Get-date).AddYears(1).12 months.ToString() + "0101"
$StartDate = [datetime]::ParseExact($strtime,"yyyyMMdd",$null)
$EndDate = [datetime]::ParseExact($endtime,"yyyyMMdd",$null)
$folderid= new-object Microsoft.Trade.WebServices.Knowledge.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,$MailboxName)
$BirthdayCalendarFolderEntryId = New-Object Microsoft.Trade.WebServices.Knowledge.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Widespread,"BirthdayCalendarFolderEntryId",[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary);
$psPropset= new-object Microsoft.Trade.WebServices.Knowledge.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$psPropset.Add($BirthdayCalendarFolderEntryId)
$EWSRootFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid,$psPropset)
$BirthdayCalendarFolderEntryIdValue = $null
$BirthdayCalendarFolderHexValue = $null
if($EWSRootFolder.TryGetProperty($BirthdayCalendarFolderEntryId,[ref]$BirthdayCalendarFolderEntryIdValue)){
$BirthdayFolderEWSId = new-object Microsoft.Trade.WebServices.Knowledge.FolderId((ConvertId -HexId ([System.BitConverter]::ToString($BirthdayCalendarFolderEntryIdValue).Substitute("-",""))))
$BirthdayFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$BirthdayFolderEWSId);
$CalendarView = New-Object Microsoft.Trade.WebServices.Knowledge.CalendarView($StartDate,$EndDate,1000)
$psPropset= new-object Microsoft.Trade.WebServices.Knowledge.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$BirthDayLocal = new-object Microsoft.Trade.WebServices.Knowledge.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Tackle,0x80DE, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::SystemTime)
$psPropset.Add($BirthDayLocal)
$CalendarView.PropertySet = $psPropset
$fiItems = $service.FindAppointments($BirthdayFolder.Id,$CalendarView)
foreach($Merchandise in $fiItems.Objects){
$exportObj = "" | Choose topic,StartTime,EndTime,DateOfBirth,Age
$exportObj.StartTime = $Merchandise.Begin
$exportObj.EndTime = $Merchandise.Finish
$exportObj.Topic = $Merchandise.Topic
$BirthDavLocalValue = $null
if($Merchandise.TryGetProperty($BirthDayLocal,[ref]$BirthDavLocalValue)){
$exportObj.DateOfBirth = $BirthDavLocalValue
$exportObj.Age = [Math]::Truncate(($Merchandise.Begin $BirthDavLocalValue).TotalDays / 365);
}
Write-Output $exportObj
}
}
else
{
throw [System.IO.FileNotFoundException] "folder not found."
}
}

}

I’ve put a duplicate of this script up on github at https://github.com/gscales/Powershell-Scripts/blob/grasp/BirthDayCalendar.ps1