-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathExample-GraphManageMessages.ps1
More file actions
18 lines (15 loc) · 874 Bytes
/
Example-GraphManageMessages.ps1
File metadata and controls
18 lines (15 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Import-Module $PSScriptRoot\..\Mailozaurr.psd1 -Force
# Example: Download attachments and archive the message
$ClientId = 'your-client-id'
$ClientSecret = 'your-client-secret'
$TenantId = 'your-tenant-id'
$cred = ConvertTo-GraphCredential -ClientId $ClientId -ClientSecret $ClientSecret -DirectoryId $TenantId
Connect-EmailGraph -Credential $cred | Out-Null
$messages = Get-EmailGraphMessage -UserPrincipalName 'user@example.com' -Filter "hasAttachments eq true" -Limit 5
foreach ($m in $messages) {
Get-EmailGraphMessageAttachment -UserPrincipalName 'user@example.com' -MessageId $m.Id |
Save-GraphMessageAttachment -Path 'C:\Temp\Attachments'
Set-GraphMessage -UserPrincipalName 'user@example.com' -MessageId $m.Id -Read
Move-GraphMessage -UserPrincipalName 'user@example.com' -MessageId $m.Id -DestinationFolderId 'Archive'
}
Disconnect-EmailGraph