Others

How to Fix the Connect-MsolService Error in PowerShell 7

Anum MushtaqAnum Mushtaq Nov 3, 2026 869 views

Question details

The user needs to resolve a type-loading error that occurs when executing the Connect-MsolService cmdlet in PowerShell 7.

How to Fix the Connect-MsolService Error in PowerShell 7
Product
PowerShell / MSOnline Module
Device & OS
not provided
Scenario
Attempting to authenticate and connect to Microsoft Online Services using PowerShell 7.
Observed behavior
The MSOnline module imports successfully, but running Connect-MsolService triggers a System.Security.Cryptography.SHA256Cng type-loading error.
Before you start

Check your current PowerShell version by typing '$PSVersionTable.PSVersion' in your console to confirm if you are running PowerShell 7 or later.

Solution 1Recommended

Switch to Windows PowerShell 5.1

Use the legacy Windows PowerShell 5.1 environment, which natively supports the MSOnline module and its dependencies.

The MSOnline module relies on .NET Framework components that are not present in the modern .NET architecture used by PowerShell 7. To run these legacy cmdlets successfully, you must use Windows PowerShell 5.1.

1
Open Windows PowerShell

Click the Start button, type 'Windows PowerShell' (ensure it does not say PowerShell 7), and select 'Run as Administrator'.

2
Import the Module

In the console, execute 'Import-Module MSOnline' to load the required cmdlets into your session.

3
Connect to the Service

Type 'Connect-MsolService' and press Enter. A prompt will appear allowing you to enter your Microsoft 365 credentials.

Switch to Windows PowerShell 5.1
Free Microsoft Office alternative

Boost Your Productivity with WPS Office

If you frequently manage IT environments, scripts, and documentation, having a reliable office suite is crucial. WPS Office is a highly compatible, lightweight alternative to Microsoft Office that allows you to easily edit, format, and share your technical documents for free.

  1. 1. Download the Installer: Visit the official WPS Office website and click the download button for your operating system.
  2. 2. Install the Software: Run the downloaded installer and follow the on-screen instructions to complete the setup.
  3. 3. Start Creating Documents: Open WPS Office and instantly start drafting scripts, reports, or data sheets with full Microsoft format support.
Fully compatible with Microsoft Word, Excel, and PowerPoint formats (.docx, .xlsx, .pptx).Lightweight design ensures fast startup without slowing down your system.Built-in PDF toolkit makes generating and reviewing technical documentation seamless.Free to use with a familiar tabbed interface to keep your workflow efficient.
microsoft office alternative - wps office

Frequently Asked Questions

Why does Connect-MsolService fail specifically in PowerShell 7?

PowerShell 7 is built on modern .NET Core, whereas the MSOnline module relies on legacy .NET Framework cryptography libraries (such as SHA256Cng). This architectural difference causes the type-loading failure when executing the connection cmdlet.

Can I force the MSOnline module to work in PowerShell 7?

No. Although PowerShell 7 features a compatibility layer for some older modules, the specific authentication mechanisms in Connect-MsolService cannot be forced to run. You must fall back to Windows PowerShell 5.1.

What is the replacement for the MSOnline PowerShell module?

Microsoft has designated the Microsoft Graph PowerShell SDK as the official replacement for both the MSOnline and Azure AD modules. It is fully supported in modern PowerShell versions.