Vorsite Cloud Services

Connecting PowerShell to Office 365

Written by cloudservicesforbusiness | 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 

-Or- 

Import-PSSession $Session –DisableNameChecking 

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

Connect-EXOPSSession –UserPrincipalName "EMAIL/Username"

*********************************************** 

Test Connection – ensure you are on the right tenant 

Get-Mailbox 

************************************************ 

Export Mailbox via CSV

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