Skip to content

Latest commit

 

History

History
64 lines (52 loc) · 2.52 KB

Simple PowerShell sample for creating an Appointment or Meeting in the Microsoft Graph.md

File metadata and controls

64 lines (52 loc) · 2.52 KB

Simple PowerShell sample for creating an Appointment or Meeting in the Microsoft Graph

In the Graph API to create an Appointment or meeting you just need to post a JSON formatted request to the events endpoint on the calendar. eg

  POST https://graph.microsoft.com/v1.0/users('gscales@datarumble.com')/calendar/events HTTP/1.1
    AnchorMailbox: gscales@datarumble.com
    Authorization: Bearer eyJ0e
    User-Agent: Mozilla/5.0 (Windows NT; Windows NT 10.0; en-AU) WindowsPowerShell/5.1.22000.282
    Content-Type: application/json
    Host: graph.microsoft.com
    Content-Length: 922

{
    "subject": "Test",
    "body": {
      "contentType": "HTML",
      "content": "One Two"
    },
    "start": {
        "dateTime":  "2022-01-25T10:34:00.6370509+11:00",
        "timeZone": "AUS Eastern Standard Time"
    },
    "end": {
        "dateTime": "2022-01-25T10:34:00.6370509+11:00",
        "timeZone": "AUS Eastern Standard Time"
    },
    "location":{
        "displayName": "Coffee Shop"
    },
    "attendees":  [
    {
        "emailAddress":  {
                             "address":  "gscales@ddd.com",
                             "name":  "gscales@ddd.com"
                         },
        "type":  "required"
    },
    {
        "emailAddress":  {
                             "address":  "glenscales@yahoo.com",
                             "name":  "glenscales@yahoo.com"
                         },
        "type":  "required"
    }
]   

}

The following sample script provides an implementation of this along with authentication code to either create an Appointment (without attendees) or a Meeting with attendees to use this

Invoke-CreateAppointment -MailboxName gscales@datarumble.com -StartTime (Get-Date) -EndTime (Get-Date).AddHours(1) -Subject "Test" -Body "One Two" -Location "Coffee Shop"

or

Invoke-CreateMeeting -MailboxName gscales@datarumble.com -StartTime (Get-Date) -EndTime (Get-Date).AddHours(1) -Subject "Test" -Body "One Two" -Location "Coffee Shop" -Attendees $attendees

Where attendees is an array of string with the attendees eg

$attendees = @()
$attendees += "ds@datarumble.com"

Note this is just simple example that can be customzied to meet other requirement (eg different timezone, optional attendees, meeting rooms etc). The sample can be found

https://github.com/gscales/Powershell-Scripts/blob/master/Graph101/CreateEvent.ps1