-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMove-O365Email.ps1
70 lines (56 loc) · 1.72 KB
/
Move-O365Email.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
<#
<-Move-O365Email->
.SYNOPSIS
Move email to other folder based of folder id's with a POST method
.DESCRIPTION
Folder is'd can be fetched with the Get-O365MailFolder
.PARAMETER AccessToken
Full token that is required this is not the path to the token but the content of the token
.PARAMETER Mailbox
Mailbox the folder should be found in
.PARAMETER EmailId
The Graph API email id which can be found with the Get-O365Email function
.PARAMETER DestiantionId
Shpuld be the id for the destionation mail folder
.PARAMETER ParentURI
This is API uri of MSGraph
.EXAMPLE
Update-O365Email -Mailbox '[email protected]' -EmailId <Email id that needs to be patched> -AccessToken <full token> -DestiantionId <targets_id>
will mark the message as read
#>
function Move-O365Email {
[CmdletBinding()]
Param(
[Parameter(
Mandatory = $true)][String]$AccessToken,
[Parameter(
Mandatory = $true)][System.Net.Mail.MailAddress]$Mailbox,
[Parameter(
Mandatory = $true)][String]$EmailId,
[Parameter(
Mandatory = $true)]$DestiantionId,
[Parameter()]$ParentURI = 'https://graph.microsoft.com/v1.0/'
)
try {
$Body = [pscustomobject]@{"destinationId" = $DestiantionId } | ConvertTo-Json
}
catch {
throw $_
}
if ($Mailbox) {
$URI = $ParentURI + "users/$Mailbox/messages/$EmailId/move"
}
else {
$URI = $ParentURI + "me/messages/$EmailId/move"
}
$Params = @{
Method = 'POST'
Header = @{
Authorization = "Bearer $AccessToken"
'Content-Type' = 'application/json'
}
Body = $body
URI = $URI
}
return Invoke-RestMethod @Params
}