What do I need to get the right powershell module for Microsoft.Graph.PowerShell.Models.IMicrosoftGraphDateTimeZone

Chito Domingo 0 Reputation points
2025-08-07T09:22:26.9+00:00

I am scripting Appointment in MS Booking and using this powershell New-MgBookingBusinessAppointment cmdlet. I am getting the following error when I try to convert the datetime to what the cmdlet is expecting. Here's the snippet of the script:

$dateTime = [System.DateTime]::Parse($startDateTimeString).ToUniversalTime()

$prop = @{

DateTime = $dateTime.ToString("yyyy-MM-ddTHH:mm:ss.fffZ") # Ensure correct format

TimeZone = $localTimeZone # Or the appropriate timezone

}

$endDateTime = New-Object -TypeName Microsoft.Graph.PowerShell.Models.IMicrosoftGraphDateTimeZone -Property $prop -ErrorAction Continue

New-Object : A constructor was not found. Cannot find an appropriate constructor for type Microsoft.Graph.PowerShell.Models.IMicrosoftGraphDateTimeZone.

At line:8 char:16

  • ... dDateTime = New-Object -TypeName Microsoft.Graph.PowerShell.Models.IM ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : ObjectNotFound: (:) [New-Object], PSArgumentException
    • FullyQualifiedErrorId : CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vasil Michev 120.9K Reputation points MVP Volunteer Moderator
    2025-08-07T10:05:38.84+00:00

    It's a simple hash-table with two (optional) values, one for the DateTime and one for the TimeZone, with both being strings. Basically, what you already have in $prop above. There is no need to cast it into any other object type

    Here's a simple example of using it with the cmdlet:

    New-MgBookingBusinessAppointment -BookingBusinessId xxxxxxxxxxxxxxxx -StartDateTime @{"DateTime" = "2025-05-01T11:30:00.0000000Z";"TimeZone" = "UTC"} -EndDateTime @{"DateTime" = "2025-05-01T12:30:00.0000000Z";"TimeZone" = "UTC"} -ServiceId 9a69b01f-4474-4de1-b8d5-75e46776929f
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.