Connect To Office 365 Using PowerShell

Microsoft 365

How can you connect to an Office 365 tenant and run O365 specific cmdlets from your workstation?

This is a question that often gets asked in forums. Let’s assume that you have a tenant in Office 365 and you would like to manage it fully using PowerShell. The O365 GUI (portal) doesn’t give you all the options anyway.

Following are the steps to get connected.

1. You need Windows 7 SP1+ or Windows 2008 R2 SP1+ server as the base operating system.

2. Install Microsoft Online Services Sign-In Assistant for IT Professionals RTW on your machine.

Microsoft Online Sign In Assistant

Microsoft Online Sign In Assistant Setup Complete

3. Install Windows Azure Active Directory Module for Windows PowerShell (32-bit version) or Windows Azure Active Directory Module for Windows PowerShell (64-bit version) depending upon the operating system version.

Windows Azure AD Module for Windows PowerShell

Windows Azure AD Module for Windows PowerShell Location

Windows Azure AD Module for Windows PowerShell Setup Complete

4. Once the installation of the Azure module is complete, there will be a PowerShell shortcut on the desktop for the same.

Windows Azure AD Module for Windows PowerShell Icon

5. Right click and select “Run as administrator”. An elevated PowerShell window will open up.

6. Change the PowerShell execution policy to RemoteSigned.

Set powershell execution policy to remotesigned

7. Connect to Office 365 by typing in Connect-MsolService. A new window will popup, enter the username and password for the global administrator account for your tenant.

Connect to O365

8. You will be returned back to your prompt in the next line and you are now connected to Office 365. No message will be displayed to that effect. Run Office 365 cmdlets to verify that the connection does work.

O365 connection using powershell successful

Alternate Method:

If you don’t want to use the Windows Azure AD Module for PowerShell icon on your desktop, you can connect using a regular powershell window.

1. After installing the sign in assistant and the Azure module for powershell (step 4 above), open a regular powershell window (run as administrator).

2. Import the Azure module by running Import-Module MSOnline

3. Connect to Office 365 by running Connect-MsolService

4. Enter the username and password for the global administrator.

5. Verify connection by running an O365 cmdlet.

Connect to Office 365 using Windows PowerShell

Now you can manage your O365 tenant fully using PowerShell ;)

Other Popular Articles


Set Edge As Default Browser Using Intune

Set Microsoft Edge As Default Browser Using Intune

Getting Started With Entra ID

Getting Started With Entra ID

How To Remove Teams Sharing Toolbar While Presenting

How To Remove Teams Sharing Toolbar While Presenting

2 thoughts on “Connect To Office 365 Using PowerShell”

  1. Hi,

    I have 10 mailboxes in “Office365 Exchange Online Plan 1”. Configured them in Outlook 2013. By default, there is a link to access the mail from OWA. Wanted to hide it from the end users. Is there any way i can do it.

    Thanks,
    Pradeep

    Reply

Leave a Comment