<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1239463409520836&amp;ev=PageView&amp;noscript=1">

Connecting PowerShell to Office 365

Posted by cloudservicesforbusiness on July 30, 2012

Last week we looked at Managing Passwords with PowerShell, this week we look at connecting PowerShell to Office 365

There are scenarios where the Admin Center and Exchange Control Panel won’t have the option you need to configure (e.g. configuring send-as or send on behalf) and using PowerShell is the only option available.  When you open PowerShell from your computer it's running a local client-side session with only the basic commands.  When connecting to the Office 365 datacenter servers, the remote server-side session downloads all the available PowerShell commands that allow you to manage your Office 365 environment.  

Assuming PowerShell is installed, configured and working correctly, here's the three lines you can use to connect a computer to Office 365 - simply copy/paste each line:

The first command captures the login identity and will initiate the username and password login window.  The second command uses that identity to login and connect to the remote PowerShell server.  The third command downloads the available PowerShell commands for Office 365 to your local computer.


Create Connection To Exchange Online 


$UserCredential = Get-Credential 


$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic –AllowRedirection 

Import-PSSession $Session 


Import-PSSession $Session –DisableNameChecking 

******************When Establishing via MFA Connection******************** 

Connect-EXOPSSession –UserPrincipalName "EMAIL/Username"


Test Connection – ensure you are on the right tenant 



Export Mailbox via CSV

get-mailbox | export-csv c:\testfilename.csv  

How Office 365 Will Improve Your Business

Subscribe Here!

Recent Posts

Posts by Tag

See all