How can I use Microsoft Graph (+PowerShell) to copy one user's calendar to a 365 Group calendar?

Darron 0 Reputation points
2024-07-15T21:32:49.4366667+00:00

Hello,

I am trying to copy events from one former employee's shared calendar to a 365 Group. I posted in the community earlier today and was directed here for further assistance.

The situation:

  • Employee 1 was part of Department A and had a created a personal calendar that the team used to track recurring deadlines and events.
    • This calendar was shared with Dept A members so they could edit, add, and view all details.
    Employee 1 left the company earlier this year, but their 365 account is still active on a basic license (web only, no desktop clients). Dept A created a new 365 Teams Group and maintain a shared calendar for the team "properly".
  • Dept A wants to use that old, shared calendar to avoid putting in all of the events individually to a new 365 Group calendar.
  • I have dabbled in PowerShell scripting and Microsoft Graph, and I have used the AD shell to work on various things, such as inviting guest users and adding them to distribution lists. However, my experience is limited.

The issue:

  • It seems we can export Employee 1's shared calendar to ics, but there is no way to import the calendar events into the 365 Group calendar.

Is there any way I can copy the events (including recurring event series') from the personal shared calendar to the new 365 Teams Group calendar? I would think perhaps there is a way to do this in PowerShell or the like but haven't found any help there. Plus, it seems like every single one of the help articles from Microsoft only apply to Outlook for web, or the older desktop Outlook client (NOT for this "New Outlook" that's been getting pushed on everyone).

Any tips or guidance (even just PS cmdlets, what object/table types to search for, example arguments for cmdlets, etc.) is greatly appreciated!

Thanks.

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
5,106 questions
Outlook
Outlook
A family of Microsoft email and calendar products.
3,998 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,258 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,583 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rohit Raghuwanshi - MSFT 625 Reputation points Microsoft Vendor
    2024-08-13T20:10:48.9133333+00:00

    Hi Darron,

    Thank you reaching out Microsoft.

    I successfully copied all events from a user's personal calendar to a group calendar using MS Graph PowerShell. Make sure to grant the following delegated permissions to retrieve a user's events and create a group calendar event:

    • Calendars.Read
    • Calendars.Read.Shared
    • Groups.ReadWrite.All

    You can use the script below after connecting to Graph PowerShell with the Connect-MgGraph command.

    $userId = "EMPLOYEE_1_USER_ID"
    $calendarId = "CALENDAR_ID"
    $events = Get-MgUserCalendarEvent -UserId $userId -CalendarId $calendarId
    $groupId = "GROUP_ID"
    foreach ($event in $events) {
         New-MgGroupEvent -GroupId $groupId -BodyParameter @{
             Subject = $event.Subject
             Start = @{
                 DateTime = $event.Start.DateTime
                 TimeZone = $event.Start.TimeZone
             }
             End = @{
                 DateTime = $event.End.DateTime
                 TimeZone = $event.End.TimeZone
             }
             Body = @{
                 ContentType = "HTML"
                 Content = $event.Body
             }
             Location = @{
                 DisplayName = $event.Location
             }
             Attendees = $event.Attendees
         }
    }
    
    

    Please refer below documents:
    https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.authentication/connect-mggraph?view=graph-powershell-1.0

    https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.calendar/get-mgusercalendarevent?view=graph-powershell-1.0

    https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.calendar/new-mggroupevent?view=graph-powershell-1.0

    Please check the attached screenshot of PowerShell Script which creates events in group calendar.
    User's image

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    0 comments No comments

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.