Last active
February 20, 2023 18:34
-
-
Save amit-g/af28b50d5e47836f8f419550e8e31b5c to your computer and use it in GitHub Desktop.
Outlook Junk Email Data
This file contains 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
Connect-MgGraph -UseDeviceAuthentication -ContextScope Process -Scopes "Mail.Read", "Mail.ReadWrite", "Mail.ReadBasic" | |
Get-MgUser | |
$UserId = (Get-MgUser).Id | |
Get-MgUserMailFolder -UserId $userId -Filter "startswith(displayName, 'Junk')" | Format-List | |
$MailFolderId = (Get-MgUserMailFolder -UserId $userId -Filter "startswith(displayName, 'Junk')" | Select-Object -First 1).Id | |
Get-MgUserMailFolderMessage -UserId $userId -MailFolderId $MailFolderId -Property "sender, subject" -Top 1000 | Select-Object @{ n='EmailDomain'; e={$_.Sender.EmailAddress.Address -Replace '[^@]+@', ''} }, @{ n='EmailAddress'; e={$_.Sender.EmailAddress.Address;} }, @{ n='Name'; e={$_.Sender.EmailAddress.Name} }, @{ n='Subject'; e={$_.Subject;} } | ConvertTo-Csv -NoTypeInformation > OutlookJunk-$(Get-Date -Format 'yyyyMMdd').csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment