How to connect on exchange online Powershell and Microsoft.Graph

This article describes how to connect to Exchange Online PowerShell both with and without multi-factor (MFA) verification using the Exchange Online PowerShell module.

The Exchange Online PowerShell module connects to all Exchange-related PowerShell environments in Microsoft 365 using modern authentication.

Firstly, we must open and run as administrator the PowerShell app

We can start with the following PS command:

Install-Module -Name ExchangeOnlineManagement -RequiredVersion 3.0.0

After that, we will get back the following option:

You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from ‘PSGallery’?

[Y] Yes  or [A] Yes to All 

For now, I chose option A

In order to load the Exchange Online PowerShell module, we run the following command:

Import-Module ExchangeOnlineManagement

The following commands may help you to connect on EXO, you may find the PS Script also to my GitHub Repo:

$ProxyOptions = New-PSSessionOption

$UserCredential = Get-Credential

Connect-ExchangeOnline -UseRPSSession -ShowBanner:$false -PSSessionOption $ProxyOptions

A new pop-up window will appear to enter your credentials

Microsoft Graph

In Microsoft 365, the hub for statistics and insight is Microsoft Graph. It provides a centralized programmability model through which you can access massive amounts of data in Microsoft 365, Windows, and Enterprise Mobility + Security. 

Now we have to Install Microsoft.Graph Module and import it to PowerShell

Install-Module Microsoft.Graph

For now, I chose option A

In order to load the Microsoft.Graph we use the following PS command:

Connect-MgGraph -Scope “User.Read.All”, “AuditLog.Read.All”

We have to consent to the permissions requested window, so check the option and accept.

Microsoft Graph provides security and intelligence to improve user productivity, creativity, and team collaboration while also protecting business resources and users’ data.

When we have done the necessary actions and we need to disconnect the PS session, we may close it with this command: Disconnect-ExchangeOnline

More info:

Connect to Exchange Online PowerShell

Microsoft Graph

More info about what is Microsoft Graph and what’s new in the public preview:

Access to comprehensive, people-centric data and insights in the Microsoft cloud, including Microsoft 365, Windows, and Enterprise Mobility + Security, is made available through the Microsoft Graph API, which has a single endpoint at To access the endpoint and create apps that serve Microsoft 365 scenarios in areas like productivity, collaboration, education, people and workplace intelligence, and more, you can utilize REST APIs or SDKs. Additionally, Microsoft Graph comes with a potent collection of services that control user and device identification, access, compliance, and security as well as assist in shielding enterprises from data loss or leakage.

In order to improve Microsoft 365 experiences like Microsoft Search, Microsoft Graph connectors operate in the incoming direction, sending data from sources outside of the Microsoft cloud into Microsoft Graph services and applications. Many frequently used data sources, including Box, Google Drive, Jira, and Salesforce, have connectors available.
A suite of technologies is offered by Microsoft Graph Data Connect to simplify and scale the transmission of Microsoft Graph data to well-liked Azure data stores. For the Azure development tools that you can use to create intelligent apps, the cached data acts as data sources.
Using REST APIs and client libraries, Microsoft Graph gives you access to the greatest Enterprise Mobility + Security, Windows, and Microsoft 365 services. Additionally, it provides analytics and security to safeguard company assets and user data while increasing user productivity, creativity, and teamwork.
At the core of Microsoft Graph are the notions of the user and group.
A user in Microsoft Graph is one among the millions who use Microsoft 365 cloud services. It is the center point, and access to it is carefully controlled and identity secured. Businesses are driven by user data. Businesses can access this data using Microsoft Graph services in rich contexts, with real-time updates, and for in-depth analyses—always only when they have the necessary permissions. The basic unit that enables collaboration amongst users is a Microsoft 365 group. It connects to other services, providing more complex scenarios for task planning, collaboration, education, and other things.
Microsoft Graph creates a network of Microsoft 365 services and features that manage, protect, and extract data to serve a variety of scenarios, starting with individuals and groups at the center. You can access this vast amount of user data with Microsoft Graph while always adhering to the appropriate authorization. There are certain services in Microsoft Graph that make their debut, while there are also some that have long been standalone services and are now integrating with Microsoft Graph.
The Microsoft Graph v1.0 and beta modules’ cmdlets will utilize different prefixes in order to enable you to create scripts that are more reliable. When building scripts, users should always rely on Microsoft Graph v1.0. Before a feature is made accessible in v1.0, testing or early adoption may occasionally be required via the beta endpoint. The Microsoft Graph beta endpoint is still in preview mode, and any feature there is subject to change. Due to the possibility of breaking current scenarios without warning, this renders the beta endpoints unstable for use in production. Therefore, keeping that in mind, you will now be able to blend production and preview simply in any script you may require, using v1.0 whenever possible and beta just where it is actually necessary. You can designate where you are using preview functionality by using prefixes. For this reason, the v1.0 module will use the same naming as the existing v1 version to prevent breaking changes for users of Microsoft Graph v1.0. Only the beta will experience changes. The new Microsoft Graph PowerShell v2 allows us to select the module that best meets our needs because the SDK is now 58% smaller. For individuals who only wish to deal with reliable APIs, the Microsoft.Graph module, which is aimed at, is the best solution. We may reach APIs we are still developing and in preview with the second one, Microsoft.Graph.Beta, which is targeted at By installing only the specific modules that your scripts will utilize rather than the complete SDK, you can further optimize your scripts. Users of PowerShell will have access to smaller packages that simplify maintenance and vastly speed up SDK installation, with advantages including, but not restricted to, CI/CD pipelines and automation on Azure. If the module targeting the Microsoft Graph v1 endpoint is used, the SDK installation size can be decreased by up to 58%. The HTTP/2 protocol also, adds support for multiplexing, header compression, and server push with the goal of enhancing performance and perceived latency. When HTTP/2 is available, users will now experience faster performance, and the SDK will gracefully fall back to HTTP/1.1 if the API does not support HTTP/2.
Users won’t be impacted by instances where the API returned a different status code than what was specified in the API documentation. By permitting all 2xx replies to be considered successful requests, success status code range support (2xx) made it feasible to access the response body when it was available for use later in the script, opening up new situations.
The SDK comes with a number of tools, libraries, and instructions that make it simple to begin developing apps that make use of the extensive data and insights made available by Microsoft Graph API.

More Info:

Leave a Reply

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