forked from Seidlm/Microsoft-Graph-API-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Set Out of Office Reply.ps1
72 lines (54 loc) · 2.02 KB
/
Set Out of Office Reply.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
$clientID = "your Client ID"
$Clientsecret = "Your Secret"
$tenantID = "your Tenant"
$UPN = "[email protected]"
$HTMLintern=@"
<html>\n<body>\n<p>I'm at our company's worldwide reunion and will respond to your message as soon as I return.<br>\n</p></body>\n</html>\n
"@
$HTMLextern=@"
<html>\n<body>\n<p>I'm at the Contoso worldwide reunion and will respond to your message as soon as I return.<br>\n</p></body>\n</html>\n
"@
#Function
#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"
}
#Set MailboxSettings
$URLSETOOF = "https://graph.microsoft.com/v1.0/users/$UPN/mailboxSettings"
#plan
$BodyJsonSETOOF = @"
{
"automaticRepliesSetting": {
"status": "Scheduled",
"scheduledStartDateTime": {
"dateTime": " 2020-08-25 12:00:00",
"timeZone": "UTC"
},
"scheduledEndDateTime": {
"dateTime": " 2021-08-25 12:00:00",
"timeZone": "UTC"
},
"internalReplyMessage": "$HTMLintern",
"externalReplyMessage": "$HTMLextern"
}
}
"@
#immediately
$BodyJsonSETOOF = @"
{
"automaticRepliesSetting": {
"status": "alwaysEnabled",
"internalReplyMessage": "$HTMLintern",
"externalReplyMessage": "$HTMLextern"
}
}
"@
$Result = Invoke-RestMethod -Headers $headers -Body $BodyJsonSETOOF -Uri $URLSETOOF -Method PATCH