Reocurring Calendar events using MSGraph and Powershell

Scott Stockton 0 Reputation points
2024-06-10T15:07:25.86+00:00

We have a CSV list of Holidays we are to inject into Exchange Online Calendars many of them are repeating events such as Ramadan for example.

The CSV is in this format:

StartDate,EndDate,Subject,StartDateMinusOne,EndDatePlusOne

2022-12-15T00:00:00,2022-12-16T00:00:00,Ramadan,2022-12-14T00:00:00,2022-12-17T00:00:00

2022-12-16T00:00:00,2022-12-17T00:00:00,Ramadan,2022-12-15T00:00:00,2022-12-18T00:00:00

I beleive it is not interpreting the operators correctly during the check to see if the event exists.

if (Get-MgUserCalendarEvent -UserID $User.id -CalendarID $Cal.Id -Filter "start/datetime ge '$ParamsStartMinusOne' and end/datetime le '$ParamsEndPlusOne' and subject eq '$ParamsSubject'") {

                Write-Host -ForegroundColor Cyan "Event: $ParamsSubject with start date: $ParamsStart already exists in $($User.UserPrincipalName) Calendar.  Skipping"

                }

            else {

                Write-Host -ForegroundColor Green "No Event: $ParamsSubject with start date: $ParamsStart found for $($User.UserPrincipalName).  Creating"

                New-MgUserCalendarEvent -UserID $User.id -CalendarID $Cal.Id -IsAllDay -Subject $params.Subject -Start $params.Start -End $params.End -ShowAs Free -IsReminderOn:$false | Out-Null
```Any help is appreciated.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,305 questions
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,590 questions
Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
549 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.