How to Connect to Office 365 Using PowerShell

There’s no shortage of articles, blog posts, and other resources out there that provide information on Windows PowerShell. Some admins might be very comfortable with the tool, while others bemoan the fact that Office 365 includes this highly technical component that goes far above and beyond the capabilities of the admin center.

The most basic thing to know about using PowerShell is that you will be interacting with a console, similar to the command line, using cmdlets (or “commandlets”) that you type in and execute by pressing Enter. Beyond that, you may use text file scripts that contain sequences of calls to cmdlets.

The video above will demonstrate how to connect to Office 365 using PowerShell so you can begin to work on your tenant, essentially following the steps you can find on this TechNet page.

  1. Verify that you meet the prerequisites: using Windows 8.1, Windows 8 or Windows 7 Service Pack 1 (SP1); global admin role in Office 365. You also must have .NET Framework 3.5.x enabled. If you have a newer version, backwards compatibility with older versions must be enabled. For more information, see Installing the .NET Framework 3.5 on Windows 8 or 8.1.
  2. Install required software: Microsoft Online Services Sign-in Assistant for IT Professionals RTW and Windows Azure Active Directory Module for Windows PowerShell (64-bit version).
  3. Find and open the Windows Azure Active Directory Module for Windows PowerShell by searching for “Azure” (either from the Search programs and files box from the start menu, or in the Search bar if you have no start menu).
  4. Type this command in the PowerShell window: $UserCredential = Get-Credential
  5. In the credential request dialog box that appears, type your Office 365 admin credentials and click OK.
  6. Type this command in the PowerShell window: Connect-MsolService -Credential $UserCredential
  7. If you didn’t see any errors, you’ve connected successfully. To test it out, run this cmdlet and check the results: Get-MsolUser

If you received errors, try these troubleshooting steps:

  1. Check your password. Run step 3 again.
  2. Ensure that the prerequisites from step 1 are installed.
  3. Your version of PowerShell might be out of date. To check, run this command: (Get-Item C:WindowsSystem32WindowsPowerShellv1.0ModulesMSOnlineMicrosoft.Online.Administration.Automation.PSModule.dll).VersionInfo.FileVersion – if the version number returned is lower than the value 1.0.8070.2, uninstall the Windows Azure Active Directory Module for Windows PowerShell, and install the latest version from the link in Step 1.
  4. If you received a connection error, see “Connect-MsolService: Exception of type was thrown” error.

We’ll provide more videos in the future on managing Office 365 through PowerShell. In the meantime, check out these resources:

Get the best tips and tricks in your inbox daily