Some useful PowerShell Commands for working with Office 365

I had to diagnose some issue that a client was having with Office 365 Exchange. A lot of features are found “under the hood” and are accessible using PowerShell. Here are some common basic comamnds that will help in connecting to your Exchange Online account. Thanks to Robert Crane, Office 365 MVP, for his helpful blog ( in getting me started.

EDIT: There are new files to be downloaded in order to get the Powershell modules (

1. Install the Azure Active Directory Modules.

2. Set up your credentials to login to Microsoft Online. $cred=get-credential

3. Connect to the Microsoft Online Service. connect-msolservice –credential $cred

4. You can now use PowerShell command to view and manage your Office 365 account.

  1. Check expiry status of all users. get-msoluser –all | format-table userprincipalname, passwordneverexpires
  2. Display a list of all contacts. Get-Contact
  3. Here is a useful command reference –  [EDIT: Now relocated here –]

5. If you need to work with Exchange Online, you can open a session by running the following two commands.

  • $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $Cred -Authentication Basic -AllowRedirection
  • Import-PSSession $Session

After this, you can manage your Exchange service with more advanced commands. For example, I had to cancel forwarding on a user account (which I could not see using the Web App or in Outlook) using the following command – Set-Mailbox -Identity <> -DeliverToMailboxAndForward $false -ForwardingSMTPAddress $null

I was also able to check the Out of Office settings using this command –

Get-Mailbox <> | Get-MailboxAutoReplyConfiguration

Leave a Reply

Your email address will not be published. Required fields are marked *

Solve the Equation to continue * Time limit is exhausted. Please reload CAPTCHA.