Appointment Creation in Specific Time Zone RRS feed

  • Question

  • I am trying to create an appointment via EWS Managed API at a specific time in a different time zone. However when I attempt to do while the appointment is in the correct time zone the time gets converted and the hour changes. In this example I am trying to create an appointment via a workstation that's set for Pacific time. The appointment I want to set is for 6pm Central time but it's being created as 8pm Central time - equivalent to 6pm Pacific time. I believe the issue is how I'm specifying the date and time using Get-Date. Here's the code:

    $mailbox = get-mailbox TargetUserIdentity
    $dllpath = "C:\program files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"
    # Init the Exchange service using the user's Time Zone per AD.
    $Service = [Microsoft.Exchange.WebServices.Data.ExchangeService]::new([system.timezoneinfo]::FindSystemTimeZoneById("Central Standard Time"))
    $Service.Credentials = [System.Net.NetworkCredential]::new($script:Credential.UserName,$script:Credential.Password)
    $Service.ImpersonatedUserID = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $mailbox.primarysmtpaddress.tostring())
    $Folder = [Microsoft.Exchange.WebServices.Data.CalendarFolder]::Bind($Service,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar)
    $appointment = New-Object Microsoft.Exchange.WebServices.Data.Appointment($service)
    $appointment.subject="Rosh Hashanah"
    $appointment.Start=(get-date -Day 18 -Month 9 -Year 2020 -Hour 18 -Minute 0 -Second 0)
    $appointment.End=(get-date -Day 20 -Month 9 -Year 2020 -Hour 18 -Minute 0 -Second 0)
    $appointment.StartTimeZone = [system.timezoneinfo]::FindSystemTimeZoneById("Central Standard Time")
    $appointment.EndTimeZone = [system.timezoneinfo]::FindSystemTimeZoneById("Central Standard Time")
    $appointment.IsAllDayEvent = $false
    $appointment.IsReminderSet = $false
    $appointment.LegacyFreeBusyStatus = []::Free

    The resultant appointment is created in Central time as desired but with a start and end time of 8pm. Of note the workstation and PowerShell instance I'm using to run this are set for Pacific time, hence what I believe is the source of the two hour difference. I am creating these appointments for users in several different time zones and so it's a pain - not to mention messy and more error-prone - to have to shift the appointment times based on the difference between Pacific time and the target time zone just to end up with the desired start and end time on the appointment I'm creating. For example, to set the start and end time in the above example to 4pm in order to end up with an appointment that starts and ends at 6pm Central.

    Thanks for your help.

    Tuesday, January 7, 2020 9:54 PM