This script allows you to export a list of all users in the tenant and all associated proxy addresses. It’s helpful to be able to get this as a csv filer for future reference so that you can quickly filter on whichever user you like. It’s also been helpful for me on a recent migration where I was able to make sure that each user’s email addresses were properly migrated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
[cc lang="powershell"]$LogFilePath = $env:LOCALAPPDATA + "\Cloudwyse\Logs\user_proxy_addresses_" + $(get-date -Format ddMMyy_HHmmss) + ".log" Start-Transcript -Path $LogFilePath -NoClobber $365Pass = cat C:\cloudwyse\securestring365.txt | convertto-securestring $365Cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "admin@contoso.com",$365Pass $DateTime = (Get-Date -Format "ddMMyyyy-HHmmss") $365Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $365cred -Authentication Basic -AllowRedirection Import-PSSession $365Session Connect-Msolservice -Credential $365Cred Write-Host -ForegroundColor Magenta "Pulling mailbox information for all users, please be patient…" $JobStart = Get-Date $getmailbox = get-Mailbox $JobEnd = Get-Date $JobSecondsTaken =($JobEnd - $JobStart) Write-Host -ForegroundColor Yellow "Extract complete. The Job took" $JobSecondsTaken.Seconds "seconds." $total = $null $Job2Start = Get-Date $userList = @() foreach ($user in $getmailbox) { $lookup = get-msoluser -userprincipalname $user.userprincipalname Write-Host -ForegroundColor Magenta "Current user is" $user.userprincipalname $addresses = $lookup.proxyaddresses foreach ($address in $addresses) { $us = New-Object PSObject $us | Add-Member -type NoteProperty -Name 'UPN' -Value $lookup.userprincipalname $us | Add-Member -type NoteProperty -Name 'ProxyAddresses' -Value $address Write-Host -ForegroundColor Cyan "Address is" $address $userList += $us } $total = $total +1 } $Job2End = Get-Date $Job2SecondsTaken =($Job2End - $Job2Start) Write-Host -ForegroundColor Yellow "$total users processed in" $Job2SecondsTaken.Minutes "minute(s) and" $Job2SecondsTaken.Seconds "second(s)." Remove-PSSession $365Session $userlist | export-csv C:\Cloudwyse\user_proxy_addresses$datetime.csv Write-Host -ForegroundColor Yellow "Report exported to C:\Cloudwyse\user_proxy_addresses$datetime.csv" Stop-Transcript[/cc] |
I’ve shared this before, but if you are unsure how to securely store credentials in a script without using plain text then follow the instructions here to create the securestring.txt.