Hello, @Mohana Reddy,
Welcome to the Microsoft Q&A platform!
Here's a general approach to extract email addresses of external users from mailboxes:
1.Connect to Exchange Online: First, ensure you have the Exchange Online PowerShell module installed. Then, connect to Exchange Online:
Connect-ExchangeOnline -UserPrincipalName ******@domain.com -ShowProgress $true
2.Retrieve External Email Addresses: You can use the following script to extract email addresses from all mailboxes. This script filters out internal email addresses based on your domain:
$domain = "yourdomain.com"
$externalEmails = @()
$mailboxes = Get-Mailbox -ResultSize Unlimited
foreach ($mailbox in $mailboxes) {
$emails = Get-MailboxFolderStatistics -Identity $mailbox.UserPrincipalName | Where-Object {$_.FolderType -eq "Inbox"} | ForEach-Object {
Get-Content -Path $_.FolderPath
}
foreach ($email in $emails) {
if ($email.SenderEmailAddress -notlike "*@$domain") {
$externalEmails += $email.SenderEmailAddress
}
}
}
$externalEmails | Sort-Object -Unique | Out-File "ExternalEmailAddresses.txt"
(Please Note: Replace "yourdomain.com"
with your actual domain. This script assumes that external email addresses do not contain your domain name and saves the unique external email addresses to a file named ExternalEmailAddresses.txt
.)
Should you need more help on this, you can feel free to post back.
If the answer is helpful, please click on “Accept answer” as it could help other members of the Microsoft Q&A community who have similar questions and are looking for solutions.
Thank you for your support and understanding.
Best Wishes,
Alex Zhang