Reocurring Calendar events using MSGraph and Powershell
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.