Articles on: Scripts

How to Connect to the Microsoft 365 Powershell

How to Connect to the Microsoft 365 Powershell



Open an elevated Windows Power Shell Comm and Prompt window (run Windows Power Shell as an administrator).



Step 1:   Run this command:

Install-Module -Name Azure AD

Step 2: Connect to Azure AD for your Microsoft 365 subscription

To connect to Azure Active Directory (Azure AD)foryourMicrosoft365run this command from a Windows Power Shell comm and prompt.

Connect-Azure AD



Connected:



Connect with the Microsoft Azure Active Directory Module for Windows PowerShell



Step 1: Install the required software or run a command

Follow these steps to install the Microsoft Azure Active Directory Module for Windows PowerShell:

1.     Open an elevated Windows Power Shell comm and prompt(run Windows Power Shell as an administrator).

2.     Run the Install-Module MS Online command.

3.     If you're prompted to install the NuGetprovider, type Y and press Enter.

4.     If you're prompted to install the module from PS Gallery, type Y and  press Enter



Step 2: Connect to Azure AD for your Microsoft 365 subscription

To connect to Azure AD for your Microsoft365 subscription with an account name and password run this command from a Windows PowerShell comm and prompt.

Connect-MsolService



Connected:



How do you know it worked?

If you don't get an error message, you connected successfully. For quick test,runaMicrosoft365cmdlet,suchasGet MsolUser, and see the results.



Your version of the Microsoft Azure Active Directory Module for Windows Power Shell might be out of date. To check, run the following command in PowerShell for Microsoft 365 or the Microsoft Azure Active Directory Module for Windows Power Shell:

(Get-Item C:\Windows\System32\WindowsPowerShell\v1.0\Modules\MSOnline\Microsoft. Online.Administration.Automation.PSModule.dll).VersionInfo.FileVersion

If you get a "Get-Item:Cannotfindpath"errormessage,run this command:

(dir "C:\Program Files\WindowsPowerShell\Modules\MSOnline").Name



It show that OFFICE 365 IS CONNECTED WITH POWERSHELL

Now connect exchange with Power shell

ThelatestversionofExchangeOnlinePowershellModule,EXOV2,thatwe are going to use supports modern authentication and will work with MFA.

The new Exchange Online PowerShell module only works on PowerShell 5.x and lower.

1.     Set the execution policy to Remote Signed:

Set-Execution Policy Remote Signed

Install the Exchange Online V2 Module in PowerShell

Install Power Shell Get ,We need to install Power Shel lGet before we can install the EXO V2Module.

Install-Module -Name Power Shell Get -Force

Install EXO V2 module , We can now install the latest Exchange Online PowerShell module with the Install-Module cmdlet

Install-Module -Name Exchange Online Management -Force

Automatically check if EXO Module is installed

(Get-Module -List Available -Name Exchange Online Management) -ne $null

**Connect to Exchange Online with PowerShell**



Connect-Exchange Online -User Principal Name admin@M365x196823.onmicrosoft.com -Show Progress $true



EXHANGE IS CONNECTED

Now connect teams with power shell

Step 1: Install Microsoft Teams PowerShell Module

Get-module*teams*

Update Teams Module: To update teams module, run:



Update-Module Microsoft Teams

Step 2: Connect to Microsoft Teams using PowerShell

Connect-Microsoft Teams



Connected:

Updated on: 08/02/2023

Was this article helpful?

Share your feedback

Cancel

Thank you!