-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathNew Outlook Appointment.ps1
112 lines (89 loc) · 2.57 KB
/
New Outlook Appointment.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
$clientID = "your Client ID"
$Clientsecret = "your Secret"
$tenantID = "your Tenant ID"
$Graph_BaseURL = "https://graph.microsoft.com/v1.0"
#Calendar User
$TargetUser="[email protected]"
#Simple Event Details
$EventSubject = "My GRAPH API Event"
$EventBody = "Thats my awesome GRAPH API Event Body"
$EventLocation = "Microsoft Headquarter"
$EventStart = "2024-02-10T09:00:00"
$EventEnd = "2024-02-10T10:00:00"
$timeZone = "UTC"
#Teams Event Details
$TeamsEventSubject = "My Teams-GRAPH API Event"
$TeamsEventBody = "Thats my awesome Teams-GRAPH API Event Body"
$TeamsEventStart = "2024-02-11T09:00:00"
$TeamsEventEnd = "2024-02-11T10:00:00"
$timeZone = "UTC"
#Authentication
#Connect to GRAPH API
$tokenBody = @{
Grant_Type = "client_credentials"
Scope = "https://graph.microsoft.com/.default"
Client_Id = $clientId
Client_Secret = $clientSecret
}
$tokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantID/oauth2/v2.0/token" -Method POST -Body $tokenBody
$headers = @{
"Authorization" = "Bearer $($tokenResponse.access_token)"
"Content-type" = "application/json"
}
$SimpleEventJson = @"
{
"subject": "$EventSubject",
"location":{
"displayName":"$EventLocation",
"address":{
"street":"4567 Main St",
"city":"Redmond",
"state":"WA",
"countryOrRegion":"US",
"postalCode":"32008"
},
},
"body": {
"contentType": "HTML",
"content": "$($EventBody)"
},
"start": {
"dateTime": "$($EventStart)",
"timeZone": "$timeZone"
},
"end": {
"dateTime": "$($EventEnd)",
"timeZone": "$timeZone"
}
}
"@
$SimpleEvent = Invoke-RestMethod -Uri "$Graph_BaseURL/users/$TargetUser/calendar/events" -Method POST -Headers $headers -Body $simpleEventJson -ContentType "application/json; charset=utf-8"
$TeamsEventJson = @"
{
"subject": "$TeamsEventSubject",
"isOnlineMeeting": true,
"onlineMeetingProvider": "teamsForBusiness",
"attendees": [
{
"emailAddress": {
"address":"[email protected]",
"name": "Ahmed Uzejnovic"
},
"type": "required"
}
],
"body": {
"contentType": "HTML",
"content": "$($TeamsEventBody)"
},
"start": {
"dateTime": "$($TeamsEventStart)",
"timeZone": "$timeZone"
},
"end": {
"dateTime": "$($TeamsEventEnd)",
"timeZone": "$timeZone"
}
}
"@
$TeamsEvent = Invoke-RestMethod -Uri "$Graph_BaseURL/users/$TargetUser/calendar/events" -Method POST -Headers $headers -Body $TeamsEventJson -ContentType "application/json; charset=utf-8"