Windows Server How-To
How To Connect to Office 365 Through PowerShell
While the process is relatively simple, the steps need to take are a bit confusing.
Several years ago, Microsoft began emphasizing that PowerShell was their preferred management tool for Windows Server environments. Being that Office 365 runs on top of Windows Server in the cloud, it should come as no surprise that it is possible to manage Office 365 using PowerShell.
PowerShell-based management for Office 365 is more than just a novelty. Some management tasks can only be performed using PowerShell. Even some of the more routine tasks such as user management may be easier if done through PowerShell.
It is relatively easy to connect to Office 365 using PowerShell. However, the tools used for doing so are somewhat not intuitive. If you want to use PowerShell to manage Office 365, you will need to download the Azure Active Directory Module for Windows PowerShell. Yes, you read that correctly. You will have to use the Azure Active Directory module to manage Windows PowerShell. Although this requirement might initially seem strange, Microsoft Azure and Office 365 are both cloud platforms that are based on Windows Server. There are enough similarities between the two environments that some of the tools that Microsoft provides will work in both Azure and Office 365.
The first thing that you will need to do is to download the Microsoft Online Services Sign-In Assistant for IT Professionals. The download and installation process is very simple, but you will need to make sure that you download the 64-bit version. Microsoft isn't going to be supporting the 32-bit version of the Windows Azure Active Directory Module for PowerShell in the future.
Once the Microsoft Online Services Sign-In Assistant has been downloaded and installed, you can download and install the Windows Azure Active Directory Module for PowerShell. Again, this is available only as a 64-bit download.
The Windows Azure Active Directory Module for PowerShell is designed to work with Windows 7 or higher, or Windows Server 2008 or higher. The method that you will use to launch this module will vary depending on the operating system that you are using. In any case, you will need to have the .NET Framework installed.
The easiest way to launch the Windows Azure Active Directory Module for Windows PowerShell in a Windows 8 environment is to expose the charms bar and then click on the Search charm. Next, enter the phrase "Windows Azure Active Directory" into the Search box. Upon doing so, Windows should provide you with a shortcut to the Windows Azure Active Directory Module for PowerShell. Click on this shortcut to launch the Windows Azure Active Directory Module for Windows PowerShell.
Upon launching the module, you will be taken to a PowerShell prompt. Although this PowerShell session has been retrofitted with a collection of Microsoft Azure related cmdlets, the session is not connected to Office 365 (or to Microsoft Azure) by default. It is up to you to establish connectivity. You can do this by entering the following cmdlet:
Upon entering this cmdlet, you should receive a prompt for your credentials. Enter your Office 365 credentials. Although a basic Admin account will work, Microsoft recommends logging in using an account that has been designated as a global administrator.
After entering your credentials, you will be taken back to the PowerShell prompt. The absence of an error message indicates a successful connection.
The thing that seems to surprise some people is that the PowerShell window does not automatically direct commands to Office 365. The cmdlets that you enter are directed to the local system by default. You have to use Azure-specific cmdlets to interact with Office 365. To see what I mean, try entering the Net User command. When you do, you will see a list of the local user accounts. The Office 365 accounts are nowhere to be found. If you want to see a list of the Office 365 user accounts, enter the following command:
This command illustrates the fact that it is possible to interact with Office 365 using PowerShell. Even so, the Get-MsolUser command is only one of many different cmdlets that are available. Microsoft provides guidance on PowerShell based management for Office 365 here.
About the Author
Brien Posey is a 21-time Microsoft MVP with decades of IT experience. As a freelance writer, Posey has written thousands of articles and contributed to several dozen books on a wide variety of IT topics. Prior to going freelance, Posey was a CIO for a national chain of hospitals and health care facilities. He has also served as a network administrator for some of the country's largest insurance companies and for the Department of Defense at Fort Knox. In addition to his continued work in IT, Posey has spent the last several years actively training as a commercial scientist-astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space. You can follow his spaceflight training on his Web site.