############################################################################### # Prerequisites: NET Framework 4.5 and Windows Management Framework 4.0 # http://technet.microsoft.com/en-us/library/jj984289.aspx # Run these commands in the following order # This will prompt you for your Exchange Online user name and password $UserCredential = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection # Corrects the "execution of scripts" error Set-Executionpolicy -ExecutionPolicy Unrestricted Import-PSSession $Session # Create the CSV file Get-mailbox -ResultSize unlimited | Select-Object Alias, Displayname, UserPrincipalName, EmailAddresses, ExchangeGUID, LegacyExchangeDN | export-csv mailbox.txt -NoTypeInformation # Run this last when you are ready to exit. Remove-PSSession $Session ###############################################################################