‘Deep Dive’ into Office 365 PowerShell cmdlets: Exchange Online Services

As powerful as Office 365 is, it can be made even more powerful with simple PowerShell cmdlets that can streamline your work and make your life easier. In today’s “Deep Dive,” we look at how to use PowerShell to manage Office 365 Exchange Online Services.

Previously in this series, we have explained the PowerShell cmdlets that you can use to manage Windows Azure Active Directory instance of an Office 365 tenant. We explained the use of Get-MsolUser, Get-MsolGroup, Add-MsolGroupMember and Remove-MsolGroupMember PowerShell cmdlets. We also explained how important Get-MsolUser PowerShell cmdlet is when it comes to collecting user information from Office 365 WAAD. Get-MsolUser PowerShell cmdlet plays an important role when collecting information such as Office 365 users licensing information, collecting membership of Office 365 users, and much more. We have provided examples of using Get-MsolUser and other cmdlets in Part 1 through Part 10. You may want to read Part 1 through Part 10 of this article series in case you need to know what Get-MsolUser cmdlet is capable of. (Links to these parts are at the end of this article.)

From this part forward, we are going to explain how you can manage other aspects of an Office 365 tenant using PowerShell. Microsoft provides the necessary PowerShell cmdlets to manage Exchange Online, SharePoint Online, Skype Online, and other services. The key here is that you need to know the PowerShell cmdlets that you can use to interact with Office 365 services. While you might have already worked with some of the Exchange Online PowerShell cmdlets, there are a few hidden PowerShell cmdlets that many Office 365 Admins are not aware of. We will start exploring PowerShell cmdlets available to manage Exchange Online Services and then move on to managing SharePoint and Skype services. In this part, we will provide the necessary steps to get you ready to work with Office 365 Exchange Online Services using PowerShell.

Managing Office 365 Exchange Online Services: Requirements

Before you can interact with Office 365 Exchange Online Services, it is important to note that there are a few requirements that you must meet:

  • You need to have a computer running either Windows 10, Windows 8, or Windows 8.1, and either Windows Server 2012, Windows Server 2012 R2, Windows 7 with Service Pack 1 or Windows Server 2008 R2 SP1.
  • Please make sure to install .NET Framework 4.5. Microsoft .NET Framework 4.5 ships with new operating systems such as Windows 10, Windows 8, Windows 8.1, Windows Server 2012, Windows Server 2012 R2 and Windows Server 2016. In case you are using an operating system other than the ones mentioned above, you can obtain .NET Framework 4.5 from here. You also need to install Windows Management Framework 4.0.
  • The PowerShell Execution Policy must be set to RemoteSigned.

Connecting to Office 365 Exchange Online

Once you have met the above requirements, it is easy as pie to connect to Office 365 Exchange Online. All you need to do is follow the steps outlined below:

  • Step 1: Set the PowerShell Execution policy to RemoteSigned by executing the command below in an elevated PowerShell window:

Set-ExecutionPolicy RemoteSigned

  • Step 2: The next step is to store the Office 365 credential in a variable. This is required in order to eliminate the need for reentering the Office 365 credentials when you perform a task against Office 365 Exchange Online. Store the Office 365 credential by issuing the command below in the PowerShell window:

$O365Creds = Get-Credential

You will be prompted to enter your Office 365 credential. Enter the Office 365 Exchange Online credential that has Organization Management rights to manage Office 365 Exchange Online Services. Note that by default, only Global Administrator has the necessary permissions to connect to Office 365 Exchange Online Services. In case you are planning to use a different user, make sure to configure the Office 365 user and give him or her appropriate rights to interact with Office 365 Exchange Online Services. To ensure the credential object was created successfully, what you can do is just type the $O365Creds in the PowerShell window. The PowerShell window should list the credential object with the username that you had used.

  • Step 3: Here, you are going to create a new PowerShell session that will connect to outlook.office365.com. Type the PowerShell  command below to store a new PowerShell session in a variable:

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

Note that in the above command, we are storing connection information in a variable. We are using the credentials stored in the $O365Creds variable to successfully authenticate against Office 365 Exchange Online.

  • Step 4: You will import the session from the $Office365Session variable by issuing the below PowerShell command:

Import-PSSession $Office365Session -DisableNameChecking

Note that the above command connects to Office 365 Exchange Online Services using the credentials stored in the $O365Creds and also imports the necessary Exchange Online PowerShell modules. As you noticed, we used “-DisableNameChecking” parameter in the above command. When you import a module or cmdlets that have unapproved verbs in their names, the PowerShell window will display a warning. The warning indicates that the some PowerShell commands have unapproved verbs that might make them less predictable. You can safely ignore the warning. All required PowerShell modules to manage Exchange Online will still be imported.

  • Step 5: At this stage, you are connected to Office 365 Exchange Online Services. To test your connection and to ensure you can interact with Office 365 Exchange Online Services, type any Exchange Online PowerShell command such as Get-MailBox. If Get-MailBox command lists the mailboxes from your Office 365 Exchange Online Management Organization, that indicates that the connection is successful and you are ready to manage Exchange Online Services using PowerShell commands.

Coming next

In the next part of this article series, we will continue to focus on Office 365 Exchange Online Services and explain some useful PowerShell cmdlets that will help you interact with Office 365 Exchange Online Services.

If you would like to read the other parts in this article series, here are the links:

Part 1, Part 2, Part 3, Part 4, Part 5, Part 6, Part 7, Part 8, Part 9, Part 10, Part 11

Nirmal Sharma

Nirmal Sharma is a MCSEx3, MCITP and was awarded the Microsoft MVP award in Directory Services and Windows Networking. He specializes in Microsoft Azure, Office 365, Directory Services, Failover Clusters, Hyper-V, PowerShell Scripting and System Center products. Nirmal has been involved with Microsoft Technologies since 1994. In his spare time, he likes to help others and share some of his knowledge by writing tips and articles on various sites.

Published by
Nirmal Sharma

Recent Posts

Qumulo raises $125M for cloud data management across a hybrid setup

Qumulo is an up-and-coming data management solution focusing on managing files in a hybrid setup.…

2 days ago

Why SMBs need a standalone solution for Windows 10 patch management

Is patch management for the Windows PCs at your business driving you crazy? Maybe there's…

2 days ago

Microsoft Teams guest access: How to enable and manage it

Two of the main factors that affect the total cost of an organization’s Microsoft 365…

3 days ago

Samsung Galaxy Unpacked 2020: Everything you need to know

Samsung rolled out the all-new Galaxy Z Fold 2, Note 20, Note 20 Ultra handsets…

3 days ago

SAN vs. NAS: Detailed comparison of these two storage technologies

SAN and NAS provide dedicated storage for a group of users using completely different approaches…

3 days ago

Generation 1 virtual machines: Modernize them and bring them up to date

In many companies, Generation 1 virtual machines have been superseded by Gen 2 VMs. But…

4 days ago