Repository navigation
Expand file tree
/
Copy pathPowerShell-Graph-GetTeamsEventInformation.ps1
More file actions
126 lines (99 loc) · 5.03 KB
/
Copy pathPowerShell-Graph-GetTeamsEventInformation.ps1
File metadata and controls
126 lines (99 loc) · 5.03 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# PowerShell-Graph-GetTeamsEventInformation.ps1
# This script demonstrates how to retrieve Team meeting information using its meeting ID via Microsoft Graph API.
# Generated initially with CoPilot.
#
# Read before trying: https://learn.microsoft.com/en-us/graph/api/resources/onlinemeeting?view=graph-rest-1.0
# Need Application permissions granted:
# OnlineMeeting.Read.All
# Be sure to do an administrator grant after setting the specific permissions.
<#
.SYNOPSIS
Get the Subject of a calendar event ("meeting") from Microsoft Graph by Event ID.
.DESCRIPTION
Uses raw REST calls to Microsoft Graph:
1) Acquire an app-only access token (client credentials).
2) GET /users/{user}/events/{eventId}?$select=subject. . .
Returns the subject string.
Docs:
- Get event API (supports $select and /users/{id|UPN}/events/{id}) [1](https://learn.microsoft.com/en-us/graph/api/event-get?view=graph-rest-1.0)
.NOTES
Permissions:
- For app-only: Calendars.Read or Calendars.ReadBasic (Application) on Microsoft Graph [1](https://learn.microsoft.com/en-us/graph/api/event-get?view=graph-rest-1.0)
- If you instead want delegated (/me/events/{id}), you’d request delegated scopes and change the URL accordingly.
#>
# =========================
# CONFIGURATION (edit these)
# =========================
# Tenant (Directory) ID (GUID)
$TenantId = "<tenant-id-guid>"
# App (client) ID (GUID)
$ClientId = "<app-id-guid>"
# Client secret (value)
$ClientSecret = "<client-secret>"
# Target mailbox that contains the meeting/event.
# You can use a UPN (user@domain.com) or a GUID id. [1](https://learn.microsoft.com/en-us/graph/api/event-get?view=graph-rest-1.0)
$UserIdOrUpn = "<user@domain.com>"
# The Graph Event ID of the meeting (this is the {id} in /events/{id})
$EventId = "<event-id>"
# =========================
# 1) Acquire token (app-only)
# =========================
# OAuth2 token endpoint for your tenant
$tokenEndpoint = "https://login.microsoftonline.com/$TenantId/oauth2/v2.0/token"
# Body for client credentials flow:
# scope must be "https://graph.microsoft.com/.default" for app-only tokens.
$tokenBody = @{
client_id = $ClientId
client_secret = $ClientSecret
scope = "https://graph.microsoft.com/.default"
grant_type = "client_credentials"
}
# Request the token
$tokenResponse = Invoke-RestMethod -Method POST -Uri $tokenEndpoint -Body $tokenBody -ContentType "application/x-www-form-urlencoded"
# Extract bearer token
$accessToken = $tokenResponse.access_token
# =========================
# 2) Call Graph Get event
# =========================
# Build the request URL.
# Use $select=subject so we only fetch what we need (smaller payload). [1](https://learn.microsoft.com/en-us/graph/api/event-get?view=graph-rest-1.0)[3](https://learn.microsoft.com/en-us/graph/query-parameters)
#$getUrl = "https://graph.microsoft.com/v1.0/users/" + $UserIdOrUpn + "/events/" + $EventId + "?`$select=subject,start,end,isOnlineMeeting,onlineMeetingProvider,onlineMeeting"
$getUrl = "https://graph.microsoft.com/v1.0/users/" + $UserIdOrUpn + "/events/" + $EventId + "?`$select=subject,start,end,isAllDay,isCancelled," +
"createdDateTime,organizer,isOrganizer,seriesMasterId, iCalUId,occurrenceId,recurrence," +
"isOnlineMeeting,onlineMeetingProvider,onlineMeeting," +
"sensitivity,responseRequested,showAs"
#$getUrl = "https://graph.microsoft.com/v1.0/users/" + $UserIdOrUpn + "/events/" + $EventId
#
# Authorization header
$headers = @{
Authorization = "Bearer $accessToken"
Accept = "application/json"
}
#
# Make the GET call
Write-Host ("Calling Graph using: {0}" -f $getUrl)
Write-Host ""
$evt = Invoke-RestMethod -Method GET -Uri $getUrl -Headers $headers
# Output Data
Write-Host "Listing Properties:"
Write-Host (" start: datetime={0} timezone={1}" -f $evt.start.dateTime, $evt.start.timezone)
Write-Host (" end: datetime={0} timezone={1}" -f $evt.end.dateTime, $evt.end.timezone)
Write-Host (" subject: {0}" -f $evt.id)
Write-Host (" isAllDay: {0}" -f $evt.isAllDay)
Write-Host (" isCancelled: {0}" -f $evt.isCancelled)
Write-Host (" type: {0}" -f $evt.type)
Write-Host (" createdDateTime: {0}" -f $evt.createdDateTime)
Write-Host (" organizer: {0}" -f $evt.organizer.emailAddress.address)
Write-Host (" isOrganizer: {0}" -f $evt.isOrganizer)
Write-Host (" seriesMasterId: {0}" -f $evt.seriesMasterId)
Write-Host (" iCalUId: {0}" -f $evt.iCalUId)
Write-Host (" uid: {0}" -f $evt.uid)
Write-Host (" occurrenceId: {0}" -f $evt.occurrenceId)
Write-Host (" recurrence: {0}" -f $evt.recurrence)
Write-Host (" isOnlineMeeting: {0}" -f $evt.isOnlineMeeting)
Write-Host (" onlineMeetingProvider: {0}" -f $evt.onlineMeetingProvider)
Write-Host (" onlineMeeting: {0}" -f $evt.onlineMeeting)
Write-Host (" onlineMeeting.joinUrl: {0}" -f $evt.onlineMeeting)
Write-Host (" sensitivity: {0}" -f $evt.sensitivity)
Write-Host (" responseRequested: {0}" -f $evt.responseRequested)
Write-Host (" showAs: {0}" -f $evt.showAs)