This guide demonstrates how to use the New-MgUserCalendarEvent cmdlet in Microsoft Graph PowerShell to create calendar events for users. Learn how to specify event details, invite attendees, and set reminders with practical examples.
The New-MgUserCalendarEvent cmdlet is a powerful tool within the Microsoft Graph PowerShell module that allows administrators to create calendar events for individual users. This cmdlet is particularly useful in scenarios where automation of personal schedules, centralized event management, and remote workforce support are necessary.
Note: You need a calendar ID to work with this cmdlet. Use Get-MgUserCalendar to get the calendar ID.
New-MgUserCalendarEvent -UserId <String> -BodyParameter <IMicrosoftGraphEvent>
This example creates a meeting scheduled in a physical location (e.g., a conference room).
$eventDetails = @{
subject = "Project Kickoff Meeting"
start = @{
dateTime = "2024-08-20T10:00:00"
timeZone = "Pacific Standard Time"
}
end = @{
dateTime = "2024-08-20T11:00:00"
timeZone = "Pacific Standard Time"
}
location = @{
displayName = "Conference Room 1"
}
attendees = @(
@{
emailAddress = @{
address = "john.doe@domain.com"
}
type = "Required"
}
)
}
New-MgUserCalendarEvent -UserId "user@domain.com" -BodyParameter $eventDetails
This example creates an online meeting using Microsoft Teams.
$eventDetails = @{
subject = "Weekly Sync"
start = @{
dateTime = "2024-08-21T14:00:00"
timeZone = "Pacific Standard Time"
}
end = @{
dateTime = "2024-08-21T15:00:00"
timeZone = "Pacific Standard Time"
}
location = @{
displayName = "Online"
}
isOnlineMeeting = $true
onlineMeetingProvider = "teamsForBusiness"
attendees = @(
@{
emailAddress = @{
address = "team.member@domain.com"
}
type = "Required"
}
)
}
New-MgUserCalendarEvent -UserId "user@domain.com" -BodyParameter $eventDetails
| Error | Cause | Solution |
|---|---|---|
| Unauthorized Access | The user executing the cmdlet does not have sufficient permissions. | Verify that the user has the required permissions (Calendars.ReadWrite or Calendars.ReadWrite.Shared). If necessary, delegate the appropriate permissions in Azure AD. |
| Invalid Time Zone | The timeZone parameter is incorrectly specified. | Use a valid time zone identifier (e.g., Pacific Standard Time, Eastern Standard Time) from the IANA time zone database. |
| Invalid Attendee Format | The email address of an attendee is not in the correct format or is missing. | Ensure that all attendee email addresses are valid and correctly formatted within the hashtable. |
Let’s break down the difference between New-MgUserEvent and New-MgUserCalendarEvent.
New-MgUserEvent:
New-MgUserCalendarEvent:
When to Use Which:
New-MgUserCalendarEvent is a Microsoft Graph PowerShell cmdlet used to create events in a user’s calendar, including specifying event details, setting reminders, and inviting attendees.
Use the following script to create a basic event:
$Body = @{
subject = "Team Meeting"
start = @{
dateTime = "2023-11-10T10:00:00"
timeZone = "UTC"
}
end = @{
dateTime = "2023-11-10T11:00:00"
timeZone = "UTC"
}
attendees = @(
@{
emailAddress = @{ address = "attendee@domain.com" }
type = "required"
}
)
}
New-MgUserCalendarEvent -UserId "<UserPrincipalName>" -BodyParameter $Body
Yes, use the recurrence property to define the recurrence pattern. Example:
$Body = @{
subject = "Weekly Sync"
start = @{
dateTime = "2023-11-10T10:00:00"
timeZone = "UTC"
}
end = @{
dateTime = "2023-11-10T11:00:00"
timeZone = "UTC"
}
attendees = @(
@{
emailAddress = @{ address = "attendee@domain.com" }
type = "required"
}
)
recurrence = @{
pattern = @{
type = "weekly"
interval = 1
daysOfWeek = @("Monday")
}
range = @{
type = "endDate"
startDate = "2023-11-10"
endDate = "2023-12-10"
}
}
}
New-MgUserCalendarEvent -UserId "" -BodyParameter $Body
You need the Calendars.ReadWrite permission in Microsoft Graph PowerShell. Ensure these permissions are granted in Azure AD.
isOnlineMeeting property and specifying onlineMeetingProvider as "teamsForBusiness" within the -BodyParameter hashtable. This allows users to instantly join meetings through Teams without manual link creation.
attendees property in New-MgUserCalendarEvent accepts an array of attendee objects. This means you can invite multiple participants in one go by passing multiple email addresses in a single command. It’s ideal for automating large-scale meeting scheduling or recurring group sessions.
The New-MgUserCalendarEvent cmdlet, while seemingly niche, offers significant value in scenarios requiring individual user calendar management. Whether it's for automating personal schedules, centralizing event management, supporting remote teams, or integrating with system notifications, this cmdlet enhances operational efficiency and ensures that important events are never overlooked.
By understanding its potential use cases, common errors, and proper implementation, administrators can leverage the New-MgUserCalendarEvent cmdlet to streamline processes and improve user experience within their organization.
© m365corner.com. All Rights Reserved. Design by HTML Codex