This guide explains how to use the New-MgUserEvent cmdlet in Microsoft Graph PowerShell to create calendar events for a user. Learn how to schedule meetings and include attendees with practical examples.
The New-MgUserEvent cmdlet allows you to create calendar events for a specific user in Microsoft 365. You can schedule various events from simple offline meetings to virtual meetings hosted via Microsoft Teams. The cmdlet leverages the -BodyParameter for inputting event details in a hashtable format. Following Microsoft's documentation conventions for this hashtable is crucial to avoid running into errors.
New-MgUserEvent -UserId <String> -BodyParameter <Hashtable>
This example demonstrates how to create an offline meeting, specifying a physical location and inviting attendees.
$params = @{
subject = "Team Sync-up Meeting"
start = @{
dateTime = "2024-09-10T10:00:00"
timeZone = "Pacific Standard Time"
}
end = @{
dateTime = "2024-09-10T11:00:00"
timeZone = "Pacific Standard Time"
}
location = @{
displayName = "Conference Room A"
}
attendees = @(
@{
emailAddress = @{
address = "john.doe@contoso.com"
name = "John Doe"
}
type = "required"
}
@{
emailAddress = @{
address = "jane.smith@contoso.com"
name = "Jane Smith"
}
type = "required"
}
)
}
New-MgUserEvent -UserId "alex.wilson@contoso.com" -BodyParameter $params
This example sets up a virtual meeting, automatically generating an online Microsoft Teams link.
$params = @{
subject = "Project Kick-off Meeting"
start = @{
dateTime = "2024-09-15T14:00:00"
timeZone = "Eastern Standard Time"
}
end = @{
dateTime = "2024-09-15T15:30:00"
timeZone = "Eastern Standard Time"
}
isOnlineMeeting = $true
onlineMeetingProvider = "teamsForBusiness"
attendees = @(
@{
emailAddress = @{
address = "sarah.lee@contoso.com"
name = "Sarah Lee"
}
type = "required"
}
)
}
New-MgUserEvent -UserId "michael.king@contoso.com" -BodyParameter $params
Cause: The date and time format provided for the start or end field may be incorrect.
Solution: Ensure that the date is in the correct ISO 8601 format (e.g., "2024-09-10T10:00:00") and that the time zone is specified accurately. Example:
start = @{
dateTime = "2024-09-10T10:00:00"
timeZone = "Pacific Standard Time"
}
Cause: The onlineMeetingProvider field is either missing or incorrectly set.
Solution: Ensure that isOnlineMeeting = $true is set and that the correct value for onlineMeetingProvider is used. For Microsoft Teams, it should be "teamsForBusiness".
isOnlineMeeting = $true
onlineMeetingProvider = "teamsForBusiness"
1. What is New-MgUserEvent used for?
New-MgUserEvent is a Microsoft Graph PowerShell cmdlet used to create new calendar events in a user’s mailbox, such as meetings or appointments.
2. How can I verify that the event was created?
Retrieve events using the Get-MgUserEvent cmdlet and filter by subject or date:
Get-MgUserEvent -UserId "<UserPrincipalName>" -Filter "subject eq 'Project Kickoff Meeting'"
3. What permissions are required to create calendar events?
You need the Calendars.ReadWrite permission in Microsoft Graph PowerShell. Ensure these permissions are granted in Azure AD.
The New-MgUserEvent cmdlet is a powerful tool for scheduling offline and online meetings in Microsoft 365. Its flexibility to handle both physical and virtual meetings makes it a core feature for automating calendar management. By following proper hashtable conventions and being mindful of parameters like time zones, event types, and attendee information, you can ensure smooth execution of this cmdlet. Leverage this cmdlet to simplify scheduling and focus on boosting productivity across your teams.
© m365corner.com. All Rights Reserved. Design by HTML Codex