Advertisement
Guest User

Untitled

a guest
Mar 13th, 2025
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. Connect-ExchangeOnline# Define the recipient type you want to query
  2. $RecipientType = "UserMailbox"# Retrieve all recipients of the specified type and their email addresses
  3. $recipients = Get-Recipient -ResultSize Unlimited -RecipientTypeDetails $RecipientType# Initialize a counter for progress tracking
  4. $Count = 0# Create an array to hold the results
  5. $results = @()# Loop through each recipient to retrieve their email addresses
  6. foreach ($recipient in $recipients) {
  7.     $Count++
  8.     $DisplayName = $recipient.DisplayName
  9.     Write-Progress -Activity "`n     Retrieving email addresses of $DisplayName.."`n" Processed count: $Count"
  10.     $RecipientTypeDetails = $recipient.RecipientTypeDetails
  11.     $PrimarySMTPAddress = $recipient.PrimarySMTPAddress
  12.     $Aliases = ($recipient.EmailAddresses | Where-Object {$_ -clike "smtp:*"} | ForEach-Object {$_ -replace "smtp:",""}) -join ","
  13.     If ($Aliases -eq "") {
  14.         $Aliases = "-"
  15.     }
  16.     
  17.     # Add the recipient's display name, primary SMTP address, and aliases to the results array
  18.     $results += [PSCustomObject]@{
  19.         DisplayName = $DisplayName
  20.         PrimarySMTPAddress = $PrimarySMTPAddress
  21.         Aliases = $Aliases
  22.     }
  23. }# Export the results to a CSV file
  24. $results | Export-Csv -Path "recipients.csv" -NoTypeInformation -Encoding UTF8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement