I am trying to run this command inside Windows PowerShell 7 :

Connect-SPOService -Url https://***-admin.sharepoint.com

But I got this error:

Connect-SPOService: Could not load type 'Microsoft.SharePoint.Client.SharePointOnlineCredentials' from assembly 'Microsoft.SharePoint.Client.Runtime, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.

Also when I tried to uninstall the module and reinstall it I got these results:

PS C:\Users\mohan> Uninstall-Module -Name Microsoft.Online.SharePoint.PowerShell
Uninstall-Package: No match was found for the specified search criteria and module names 'Microsoft.Online.SharePoint.PowerShell'.
PS C:\Users\mohan> Install-Module -Name Microsoft.Online.SharePoint.PowerShell

Untrusted repository
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
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): A
WARNING: Version '16.0.23311.12000' of module 'Microsoft.Online.SharePoint.PowerShell' is already installed at 'C:\Program Files\WindowsPowerShell\Modules\Microsoft.Online.SharePoint.PowerShell\16.0.23311.12000'. To install version '16.0.23508.12000', run Install-Module and add the -Force parameter, this command will install version '16.0.23508.12000' side-by-side with version '16.0.23311.12000'.

PS C:\Users\mohan> Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ListAvailable | Select Name,Version

Name                                   Version
----                                   -------
Microsoft.Online.SharePoint.PowerShell 16.0.23311.12000
Microsoft.Online.SharePoint.PowerShell 16.0.22601.12000
Microsoft.Online.SharePoint.PowerShell 16.0.22315.12000

So how can I run Connect-PnPService inside Windows PowerShell 7?

  • 1
    You seem to have multiple versions installed, have you tried uninstalling them all and installing only one version? May 4 at 11:24
  • @CallumCrowley yes and this what i get :( stackoverflow.com/questions/76172196/… May 4 at 11:27
  • 1
    that question refers to PnP.PowerShell not Microsoft.Online.SharePoint.PowerShell May 4 at 11:39
  • 1
    You are mixing up the things. There is no such command like: Connect-PnPService. You have Connect-SPOService in SPO PowerShell and you have to run it via SharePoint Online Management Shell only May 4 at 13:07
  • 1
    Read my above comment again carefully. Its Connect-SPOService and not Connect-PnPService. May 4 at 14:17

2 Answers 2


For PowerShell 7, you have to use the Windows PowerShell Compatibility feature because the Microsoft.Online.SharePoint.PowerShell module was built with .NET Framework and not .NET Core.

The way this works is you have to import the module into PowerShell 7 with an additional switch, as in the following example:

Import-Module Microsoft.Online.SharePoint.PowerShell -UseWindowsPowerShell

You may get an error that the module was not found in any module directory. If that happens, it means you must first switch to Windows PowerShell and install the module so that it is copied to the Windows PowerShell module directory on your system, which is different than the directory used by PowerShell 7. After that, you should be good to go.


I will suggest you to use the SharePoint Online Management Shell for running the SharePoint Online PowerShell commands like Connect-SPOService.

You can install the SharePoint Online Management Shell by downloading and running the SharePoint Online Management Shell or installing the module from the PowerShell Gallery.

Documentation: Get started with SharePoint Online Management Shell


You have to use the PowerShell 7.2 or later to use the PnP PowerShell commands like Connect-PnPOnline.

Documentation: PnP PowerShell Installation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.