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 (http://blog.ciaops.com/2012/09/configuring-power-shell-access-in.html) in getting me started.

EDIT: There are new files to be downloaded in order to get the Powershell modules (https://support.office.com/en-US/article/Windows-PowerShell-cmdlets-for-Office-365-06a743bb-ceb6-49a9-a61d-db4ffdf54fa6)

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 – http://onlinehelp.microsoft.com/office365-enterprises/hh125002  [EDIT: Now relocated here – http://aka.ms/aadposh]

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 https://ps.outlook.com/powershell/ -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 <mailbox@mydomain.com> -DeliverToMailboxAndForward $false -ForwardingSMTPAddress $null

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

Get-Mailbox <mailbox@mydomain.com> | 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.