Updating a Group Event in MS Graph - Cannot get date format correct

John Clark 20 Reputation points
2023-06-10T20:12:45.0233333+00:00

I have written a PowerShell script to add an end date to a recurring event for the Teams group of my choosing. The problem I am running into is when I run the Update-MgGroupEvent command, I get the following message:

Update-MgGroupEvent : Recurrence end date can not exceed Sep 1, 4500 00:00:00.

Here is the relevant line from my script:

Update-MgGroupEvent -EventId $mostRecentEvent.Id -GroupId $teamID -Recurrence $updateRecurrence

The variable $updateRecurrence is a hashtable that currently looks like this:

{
    "range":  {
                  "enddate":  {
                                  "DateTime":  "2023-05-22T12:00:00",
                                  "TimeZone":  "Eastern Standard Time"
                              },
                  "type":  "endDate"
              },
    "pattern":  {
                    "DayOfMonth":  0,
                    "DaysOfWeek":  [
                                       "monday"
                                   ],
                    "FirstDayOfWeek":  "sunday",
                    "Index":  "first",
                    "Interval":  1,
                    "Month":  0,
                    "Type":  "weekly"
                }
}

The hashtable printout is courtesy of

Write-Host($updateRecurrence | ConvertTo-Json)

I'm a relative beginner with PowerShell, hashtables are new to me (although the key, value paradigm is quite familiar), and I'm just now getting into writing scripts using the MS Graph API. So, I will take no offense if you speak to me like you're explaining it to a first grader. 🙂

Also, I'm not sure whether or not the "pattern" part of the hashtable needs to be there since I am not updating anything.

Thanks,

John

Windows 10.0.19045, PowerShell 5.1.19041.2673

Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Graph
Microsoft Teams | Microsoft Teams for business | Other
0 comments No comments
{count} votes

Accepted answer
  1. Vasil Michev 119.9K Reputation points MVP Volunteer Moderator
    2023-06-11T15:11:28.85+00:00

    You can simply copy the existing value, and replace whichever property you need to. Be mindful of the date format though. For example, to replace the end date for a given series, you can do something like this:

    $hash = $event.Recurrence
    $hash.Range.EndDate = Get-Date("01 Jul 2023") -Format s
    $hash.Range.Type = "endDate"
    

    where $event is the series object, as retrieved via Get-MgGroupEvent. Once the end date is changed, pass the updated hash as value:

    Update-MgGroupEvent -GroupId GUID -EventId $event.id -Recurrence $hash

    In this case, you do have to include the pattern part as well, as it's all considered as one property.


0 additional answers

Sort by: Most helpful

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.