Last active
March 3, 2023 19:14
-
-
Save bill-long/a0b889e49c0edb935a7ba61b25b363b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -Modules Microsoft.Graph, Microsoft.Graph.Users.Actions | |
Connect-MgGraph -Scopes "User.Read.All", "Mail.ReadBasic", "Mail.Read", "Mail.ReadWrite" -DeviceAuth -ContextScope Process | |
$userId = (Invoke-MgGraphRequest -Uri "v1.0/me")["id"] | |
# Only returns 10 items by default | |
Get-MgUserMessage -UserId $userId | ft ReceivedDateTime,Subject | |
# You can filter for stuff older than a certain date | |
Get-MgUserMessage -UserId $userId -Filter "ReceivedDateTime lt 2023-01-25" | ft ReceivedDateTime,Subject | |
# Then you can pipe that to foreach and perform some action. | |
# In this example we move the first result to the Archive folder (the one-click archive, NOT the archive mailbox). | |
Get-MgUserMessage -UserId $userId -Filter "ReceivedDateTime lt 2023-01-25" | Select -First 1 | % { Move-MgUserMessage -DestinationId archive -UserId $userId -MessageId $_.Id } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment