Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connect-ExchangeOnline# Define the recipient type you want to query
- $RecipientType = "UserMailbox"# Retrieve all recipients of the specified type and their email addresses
- $recipients = Get-Recipient -ResultSize Unlimited -RecipientTypeDetails $RecipientType# Initialize a counter for progress tracking
- $Count = 0# Create an array to hold the results
- $results = @()# Loop through each recipient to retrieve their email addresses
- foreach ($recipient in $recipients) {
- $Count++
- $DisplayName = $recipient.DisplayName
- Write-Progress -Activity "`n Retrieving email addresses of $DisplayName.."`n" Processed count: $Count"
- $RecipientTypeDetails = $recipient.RecipientTypeDetails
- $PrimarySMTPAddress = $recipient.PrimarySMTPAddress
- $Aliases = ($recipient.EmailAddresses | Where-Object {$_ -clike "smtp:*"} | ForEach-Object {$_ -replace "smtp:",""}) -join ","
- If ($Aliases -eq "") {
- $Aliases = "-"
- }
- # Add the recipient's display name, primary SMTP address, and aliases to the results array
- $results += [PSCustomObject]@{
- DisplayName = $DisplayName
- PrimarySMTPAddress = $PrimarySMTPAddress
- Aliases = $Aliases
- }
- }# Export the results to a CSV file
- $results | Export-Csv -Path "recipients.csv" -NoTypeInformation -Encoding UTF8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement