Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

How to Connect to Microsoft 365 using Windows PowerShell

July 25, 2022
in Entra ID, Microsoft 365, Powershell
0
ADVERTISEMENT

Table of Contents

PowerShell for Microsoft 365 enables you to manage your Microsoft 365 settings from the command line. To connect to PowerShell, just install the required software and then connect to your Microsoft 365 organization.

There are two versions of the PowerShell module that you can use to connect to Microsoft 365 and administer user accounts, groups, and licenses:

  • Azure Active Directory PowerShell for Graph, whose cmdlets include AzureAD in their name.
  • Microsoft Azure Active Directory Module for Windows PowerShell, whose cmdlets include Msol in their name
Note Note: Currently, the Azure Active Directory PowerShell for Graph module doesn't completely replace the functionality of the Microsoft Azure Active Directory Module for Windows PowerShell module for user, group, and license administration. In some cases, you need to use both versions. You can safely install both versions on the same computer.

Requirements

  • You should use PowerShell on Windows 10 or Windows 11. Be aware that you need to install .NET Framework 4.5 or later.
  • An internet connection is required. TCP port 80 must be opened to connect from your local machine to the destination host.
  • Access to Exchange Online PowerShell must be enabled for the current user (by default such access is enabled for administrators).

Connect to Microsoft 365 PowerShell (MSOL)

1. Right click on Windows icon then select Windows PowerShell Admin. In Windows 11, select Windows Terminal Admin instead of Windows PowerShell Admin.

Pw3

2. Copy then paste all below commands into PowerShell window at once then hit Enter to install modules then connect to MSOnline PowerShell.

Note You need install MSOnline module only once. In the next time, run Connect-MsolService to connect to Entra ID PowerShell.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force;
Install-PackageProvider -Name NuGet -Force;
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted;
Install-Module -Name MSOnline;
Connect-MsolService;
3. In the sign-in window that opens, enter your Global Admin credential then click .
Bg488
ADVERTISEMENT

How do you know this worked

A quick test is to run an Azure Active Directory PowerShell cmdlet, for example, Get-MsolUser, and see the results.

PS C:\Users\mpnadmin> Get-MsolUser

UserPrincipalName                    DisplayName       isLicensed
-----------------                    -----------       ----------
[email protected]     Lidia Holloway    True
[email protected]     Diego Siciliani   True
[email protected]     Adele Vance       True
[email protected]      Alex Wilber       True
[email protected] Henrietta Mueller True
[email protected]     Grady Archie      True
[email protected]      Bon Guides        True

Connect to Microsoft 365 PowerShell (AzureAD)

1. Open an elevated Windows PowerShell Command Prompt window (run Windows PowerShell as an administrator) then Run this command:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force;
Install-PackageProvider -Name NuGet -Force;
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted;
Install-Module -Name AzureAD;
Import-Module AzureAD;
Connect-AzureAD

2. After you connect, you can use the cmdlets for the Azure Active Directory PowerShell for Graph module.

Install two modules at once

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force;
Install-PackageProvider -Name NuGet -Force;
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted;
Install-Module -Name MSOnline;
Install-Module -Name AzureAD;
Import-Module AzureAD;
5/5 - (1 vote)
Previous Post

How to Fix Entra ID Connect Attribute Value Must be Unique Office 365

Next Post

How to fix CentOS 6 error YumRepo Error All Mirror URLs are Not using FTP, https

Related Posts

Ftr38

How to Get Environment Variable Values Using PowerShell

July 22, 2024
Ftr38

How to Print PATH Environment Variables to The Console in PowerShell

July 25, 2024
Ftr38

How to Create Persistent Environment Variables in Windows

July 26, 2024
Ftr38

How to Get the PATH Environment Variables Using PowerShell

July 25, 2024
Ftr5

How to Set Environment Variable in Windows Using CMD & PowerShell

July 26, 2024
Ftr38

How to Add a Directory to Windows %PATH% Environment Variables

July 23, 2024

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory