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:
- 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.
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: