Connect to Exchange Online
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://outlook.office365.com/powershell-liveid/ -Authentication Basic -AllowRedirection:$true -Credential $UserCredential
Import-PSSession $Session -DisableNameChecking:$true -AllowClobber:$true | Out-Null
Get all Exchange Online users
$AllUsers = Get-Mailbox -ResultSize Unlimited
Iterate through each user and retrieve email address aliases
foreach ($User in $AllUsers) {
$UserPrincipalName = $User.UserPrincipalName
$PrimarySMTP = $User.PrimarySmtpAddress
$EmailAliases = $User.EmailAddresses
# Output the information
Write-Host "User: $UserPrincipalName"
Write-Host "Primary SMTP: $PrimarySMTP"
Write-Host "Email Aliases: $($EmailAliases -join ', ')"
Write-Host "----------------------------------------"
}
Disconnect from the Exchange Online session
Remove-PSSession $Session
Please note:
- This script requires you to enter your credentials when prompted. Ensure that the account has the necessary permissions to access Exchange Online. You can use Global Admin account.
- Make sure you have the Exchange Online PowerShell module installed. You can install it by following the instructions here: Connect to Exchange Online PowerShell.
- The script uses the
Get-Mailboxcmdlet to retrieve all Exchange Online users. Adjust the parameters as needed based on your requirements. - The script outputs the user’s principal name, primary SMTP address, and a list of email aliases.
Remember to test scripts in a controlled environment before using them in a production environment.
Leave a comment