The New-MgUserCalendar cmdlet in Microsoft Graph PowerShell is designed to create a new calendar for a specified user. This cmdlet is particularly useful for administrators who need to manage user calendars programmatically within a Microsoft 365 environment. In this article, we'll dive into the syntax, provide usage examples, discuss cmdlet tips, explore common errors and solutions, and review potential use cases.
New-MgUserCalendar -UserId <String> -BodyParameter <IMicrosoftGraphCalendar>
This example creates a new calendar named "Team Meetings" for the specified user.
$CalendarDetails = @{
Name = "Team Meetings"
Color = "Auto"
}
New-MgUserCalendar -UserId "john.doe@company.com" -BodyParameter $CalendarDetails
In this example, a calendar named "Project Deadlines" is created with specific permissions set for other users.
$CalendarDetails = @{
Name = "Project Deadlines"
Color = "LightBlue"
PermissionLevel = "CanView"
}
New-MgUserCalendar -UserId "jane.smith@company.com" -BodyParameter $CalendarDetails
This example demonstrates creating a calendar with specific time zone settings and restricting online meeting providers to Microsoft Teams.
$CalendarDetails = @{
Name = "International Meetings"
Color = "LightRed"
TimeZone = "Pacific Standard Time"
AllowedOnlineMeetingProviders = @("TeamsForBusiness")
}
New-MgUserCalendar -UserId "sara.connor@company.com" -BodyParameter $CalendarDetails
Cause: The specified -UserId does not match any user in the tenant.
Solution: Double-check the user ID or UPN for accuracy. Use the Get-MgUser cmdlet to verify the user exists.
Cause: The -BodyParameter contains invalid or unsupported calendar properties.
Solution: Review the properties passed in the hashtable. Ensure they align with the supported properties listed in the Microsoft Graph API documentation.
Cause: Insufficient permissions to create calendars on behalf of users.
Solution: Ensure the account running the script has the necessary permissions, such as the Calendars.ReadWrite scope.
The New-MgUserCalendar cmdlet is a powerful tool for managing user calendars in a Microsoft 365 environment. Whether you're creating individual calendars for specific users or bulk-generating calendars for multiple employees, this cmdlet provides the flexibility and control needed for efficient calendar management.
© m365corner.com. All Rights Reserved. Design by HTML Codex