How to Set Up Calendar Permissions for Multiple Users in Microsoft Graph?
Asked by
LearningCodeNinja99
I'm diving into Microsoft Graph and trying to grant write access to six users so they can modify each other's primary calendars. I've come across an error, specifically: "Cannot process argument transformation on parameter 'CalendarId'. Cannot convert value to type System.String." I've attached a snippet of my code, where I'm looping through the users and using the Get-MgUserCalendar and Get-MgUserCalendarPermission commands. Any suggestions on what might be going wrong?
Answers
It looks like you're trying to fetch the user calendar permission but the CalendarId might not be formatted correctly as a string. Try using `$existingPerm = Get-MgUserCalendarPermission -UserId $targetUser -CalendarId "$($primaryCalendar.id)"` to force it to convert into a string. You might also want to print out what `$primaryCalendar.id` returns just to be sure it's what you expect.
Reply to this answer
I noticed you set `$primaryCalendar` as an array first and then immediately overwrite it with a single calendar. This could lead to confusion. Since you're targeting one user's primary calendar, you should just assign it directly and avoid the array initialization. Also, make sure that `$primaryCalendar.id` is indeed a single string and not multiple values.
Reply to this answer
Your error indicates that `$primaryCalendar.id` isn't a string. This can happen if there are multiple calendars returned for a user. Check the contents of `$primaryCalendar` to see if itโs returning more than one calendar and ensure you're pointing to the correct one.
Reply to this answer
Since you're using M365 accounts, consider managing these permissions directly through the MS 365 admin portal or the Exchange Online module for a more straightforward process. Leveraging Microsoft Graph can be tricky at first, especially with permission handling.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions