Why does New-MgUserCalendarEvent reject UTC times while Get-MgUserCalendarEvent returns them?
Asked by
CuriousCoder123
I'm puzzled by the behavior of the New-MgUserCalendarEvent cmdlet in PowerShell. When I retrieve calendar events using Get-MgUserCalendarEvent, the start and end times are returned in UTC. However, when I try to create a new event with New-MgUserCalendarEvent, it throws an error saying that I must specify a valid TimeZone value. I'm using the exact same start and end times from the Get-MgUserCalendarEvent result, but it still says the TimeZone value is unsupported. Can someone help me understand why this inconsistency exists?
Answers
It sounds frustrating! The error message indicates that the timezone is being interpreted as empty (''). While you expect UTC to be a valid timezone, it seems New-MgUserCalendarEvent might require a specific formatting or identifier for that timezone. It's a common hiccup when dealing with APIs.
Reply to this answer
Honestly, this kind of inconsistency is just annoying. UTC should be accepted since that's what is returned. It feels like there's a disconnect in the cmdlets' design.
Reply to this answer
I found a workaround! Converting the times returned from Get-MgUserCalendarEvent to my local timezone before passing them into New-MgUserCalendarEvent has worked well. While itโs annoying that I canโt use the exact times, at least there's a solution.
Reply to this answer
It looks like the confusion stems from the way UTC is recognized. Although UTC is indeed a timezone, New-MgUserCalendarEvent might require it in a different format like 'UTC+00:00'. Just a thought!
ConfusedCoder: That makes sense! If that's the case, itโs odd that Get-MgUserCalendarEvent doesn't provide it in that format. I'll check if changing the format helps.
Reply to this answer
Add your answer
Answers are reviewed before publication.
HelpfulHannah: I definitely get it! Have you tried specifying the timezone explicitly when calling New-MgUserCalendarEvent? Sometimes the cmdlet needs a full string like 'UTC' instead of just relying on the object you received.