powershelloffice365exchange-serverexchangewebservicesews-managed-api

how to create recurring meeting weekly, monthly and yearly in exchange mailbox calendar using EWS Managed API in PowerShell


I am trying to create an Exchange mailbox calendar meeting using EWS Managed API in PowerShell. I am able to create if it is not a recurring meeting but the code is not working for recurrence. I see there are multiple examples of creating recurring meetings in C# but I could not find much help to work recurrence in PowerShell.

When I tried this code. I am getting the error, screenshots are attached.

$recurrence = New-Object Microsoft.Exchange.WebServices.Data.Recurrence ($Appointment.Start.Date, [Microsoft.Exchange.WebServices.Data.DayOfTheWeek]::Wednesday, 1) $Appointment.Recurrence = $recurrence

enter image description here

I also tried this code $Recurrence = New-Object Microsoft.Exchange.WebServices.Data.Recurrence.WeeklyPattern([Microsoft.Exchange.WebServices.Data.DayOfTheWeek]::Tuesday, 1) $Appointment.Recurrence = $Recurrence

But got the error enter image description here

I am really fed up with this issue because many days have passed and I am still stuck there. EWS Managed API DLL is being loaded and working properly when I create a simple meeting without any recurrence. Any help would be appreciated. Thanks


Solution

  • Recurrence (and SearchFilters) in the EWS Managed API are nested types see https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/nested-types?redirectedfrom=MSDN. But basically you can't create an instance of the enclosing type (as there are no public constructors) eg you can check that in PowerShell using (or just read the source code or documentation for the class)

    ([type]"Microsoft.Exchange.WebServices.Data.Recurrence").GetConstructors()
    

    To use nested types in PowerShell you just add a + sign between the enclosing type and nested type eg

    Microsoft.Exchange.WebServices.Data.Recurrence+WeeklyPattern
    

    For the weeklypattern the constructor is documented https://learn.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.recurrence.weeklypattern.-ctor?view=exchange-ews-api#microsoft-exchange-webservices-data-recurrence-weeklypattern-ctor(system-datetime-system-int32-microsoft-exchange-webservices-data-dayoftheweek()) so in your example it is missing the StartDate for the recurrence eg it should be

    $Recurrence = New-Object Microsoft.Exchange.WebServices.Data.Recurrence+WeeklyPattern((Get-Date),1,[Microsoft.Exchange.WebServices.Data.DayOfTheWeek]::Tuesday)