Fix “Connect-SPOService : The term ‘Connect-SPOService’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.” Error

Problem: When trying to connect to the SharePoint Online site through the PowerShell cmdlet: Connect-SPOService -URL https://crescent-Admin.SharePoint.com, got an error message and could not connect to SharePoint Online from PowerShell:

Connect-SPOService : The term ‘Connect-SPOService’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Here is the Full error message:

Connect-SPOService: The term 'Connect-SPOService' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path

Root cause:

The error “Connect-sposervice is not recognized as the name of a cmdlet” occurs when the SharePoint Online Management Shell module is not installed or loaded in the current PowerShell session. To resolve this error, follow these steps:

Solution:

This error message indicates that the particular cmdlet doesn’t exist in the loaded modules. In this case, this error is because the “Connect-SPOService” cmdlet is part of SharePoint Online Management Shell (or SharePoint Online PowerShell Module), and it is not loaded! So, to resolve this issue: You have to install either the SharePoint Online Management Shell (less recommended) or SharePoint Online PowerShell Module (Preferred) before using the cmdlet Connect-SPOService to connect to SharePoint Admin Center.

Option 1: Download and Install SharePoint Online Management Shell

You can download and install SharePoint Online Management Shell to your client machine from https://www.microsoft.com/en-us/download/details.aspx?id=35588

install sharepoint online management shell powershell

If it’s already installed, try uninstalling and then re-installing.

Option 2: Install SharePoint Online PowerShell Module

Double-check if the SharePoint Online PowerShell Module is installed by:

Get-Module -ListAvailable -Name Microsoft.Online.SharePoint.PowerShell | Select Name,Version

You can install the SharePoint Online PowerShell Module with the following:

Install-Module Microsoft.Online.SharePoint.PowerShell 

For uninstallation, use:

Uninstall-Module -Name Microsoft.Online.SharePoint.PowerShell -AllVersions -Force

This will install necessary assemblies (.dll files) to the path: C:\Program Files\WindowsPowerShell\Modules\Microsoft.Online.SharePoint.PowerShell\<Build-Number>

Other Workarounds:

Although we don’t have to explicitly load the module in PowerShell with “Import-Module Microsoft.Online.SharePoint.Powershell”, give it a try to expose any potential issues.

If you are trying to connect to the SharePoint site from PowerShell through a proxy server, the Connect-SPOService cmdlet connections fail! You have to use the following method to connect to SPO Service:

#Get Credentials to connect
$cred = Get-Credential
[System.Net.WebRequest]::DefaultWebProxy.Credentials = $cred

#Connect to SharePoint Online Administration Center
Connect-SPOService -Url "https://<Tenant-admin>.sharepoint.com" -Credential $cred

In another situation, I had to delete all different versions of SharePoint Online client Assemblies from the Global Assembly Cache (GAC) and then install the SharePoint Online PowerShell Module:

  1. Navigate to “C:\Windows\Microsoft.NET\assembly\GAC_MSIL”
  2. Select all folders starting with the name “Microsoft.SharePoint.Client” and delete them all!
  3. Finally, Install the PowerShell Module for SharePoint Online: Install-Module Microsoft.Online.SharePoint.PowerShell -force
Make sure you have closed all PowerShell/PowerShell ISE instances before performing the above steps, and restart the PowerShell console or PowerShell ISE after the installation.

Different file versions could cause it. You can confirm you don’t have any SharePoint DLLs in the GAC directory with the following script:

Get-ChildItem -Path C:\Windows\Microsoft.NET\assembly\GAC_MSIL\*Microsoft.SharePoint*.dll -Recurse | ft Name,@{Label="Version";Expression={$_.VersionInfo.FileVersion}} -AutoSize

Wrapping up

In conclusion, the error “Connect-SPOService is not recognized as the name of a cmdlet” in SharePoint Online PowerShell can be resolved by installing the SharePoint Online Management Shell and loading the module in the current PowerShell session. By following the steps outlined in the above answer, the error can be resolved, and the Connect-SPOService cmdlet can be used to connect to SharePoint Online.

How to install the PnP module in PowerShell?

To install the PnP PowerShell module for SharePoint Online, Run “Install-Module -Name PnP.PowerShell” as Administrator in the PowerShell console. Once installed, You can connect to SharePoint Online from PnP PowerShell using Connect-PnPOnline.

How do I Connect to SPOService using MFA enabled account?

To connect to SharePoint Online using PowerShell with an MFA-enabled account, you can use the Connect-SPOService cmdlet without the -Credential parameter. This will prompt you to enter your username and password and MFA code. Here’s an example:
Connect-SPOService -Url https://YourTenant-admin.sharepoint.com

How to get items from a SharePoint Online list using PowerShell?

To get items from a SharePoint Online list using PowerShell, you can Connect to SharePoint Online using PnP PowerShell >> Use the Get-PnPListItem cmdlet to retrieve all items in the list >> Filter the items based on your requirements. Here is an example:
Connect-PnPOnline -Url https://yourtenant.sharepoint.com -Interactive
$ListItems = Get-PnPListItem -List "YourListName"
$FilteredItems = $ListItems | Where-Object { $_.Title -like "YourFilter" }

How to get users from SharePoint Online site using PowerShell?

To get all users from a SharePoint Online site using PowerShell, you can use the “Get-PnPUser” cmdlet from PnP PowerShell or Get-SPOUser cmd in SharePoint Online Management Shell.

How do I get all the libraries in SharePoint PowerShell?

To get all libraries in SharePoint using PowerShell, you can utilize CSOM or PnP PowerShell methods depending on your requirements: You have to Connect to SharePoint Online using PnP PowerShell, Use the Get-PnPList cmdlet to retrieve all document libraries, and then filter the results based on the library type. Here is an example script: $DocLibs = Get-PnPList | Where-Object {$_.BaseType -eq “DocumentLibrary”}

What is the difference between SharePoint Online Management Shell and PnP PowerShell?

SharePoint Online Management Shell is the official module for SharePoint Online administration. At the same time, PnP PowerShell is an open source community project that covers a broader range of Microsoft 365 services, including SharePoint Online.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

11 thoughts on “Fix “Connect-SPOService : The term ‘Connect-SPOService’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.” Error

  • thanks, I found this helpful. I do have a question. The older command on Connect-PnPonline works well with my MFA-enabled admin account, Connect-PnPOnline -Url $SiteURL -UseWebLogin. but I haven’t found an equivalent way of using Connect-SPOService without prompting for MFA like the old pnponline command. Any ideas?

    Reply
  • Hello, try do Connect-PnPOnline comands.

    Reply
  • Same here, nothing I’ve been at this 48 hours and it doesn’t matter what I’ve try all I ever get is ‘Connect-SPOService’ is not recognized OVER AND OVER AGAIN.

    Reply
  • Every time I connect-SPOService I get this error. I fix it following these steps. Than next time I open powershell, I get the error again and have to follow these steps again.

    Reply
  • Tried all, to no avail.
    Could this have to do with Powershell 7 and up? and the location where it is installed

    Reply
  • I have tried all the steps mentioned, the issue still exists in windows 10 machine

    Reply
  • I am also facing the same issue. None of SharePoint Online commands seem to be working.Import-Module : Could not load type ‘Microsoft.SharePoint.Client.Publishing.PortalLaunch.PortalLaunchRedirectionType’ from
    assembly ‘Microsoft.SharePoint.Client.Publishing, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’.
    Connect-SPOService : The term ‘Connect-SPOService’ is not recognized as the name of a cmdlet, function, script file, or
    operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.Connect-SPOService : The term ‘Connect-SPOService’ is not recognized as the name of a cmdlet, function, script file, or
    operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    Reply
  • is there any fix for this issue.? I am having this problem as well.

    import-module : Could not load type ‘Microsoft.SharePoint.Client.Publishing.PortalLaunch.PortalLaunchRedirectionType’ from assembly ‘Microsoft.SharePoint.Client.Publishing, Version=16.0.0.0, Culture=neutral,
    PublicKeyToken=71e9bce111e9429c’.
    At line:1 char:1
    import-module microsoft.online.sharepoint.powershell
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CategoryInfo : NotSpecified: (:) [Import-Module], TypeLoadException
    FullyQualifiedErrorId : System.TypeLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand

    #Read more: https://www.sharepointdiary.com/2019/02/the-term-connect-sposervice-is-not-recognized-as-the-name-of-a-cmdlet-function-script-file-or-operable-program.html#ixzz6jrU5uBTe

    i have uninstalled and reinstalled SharePoint powershell module and still cannot use connect-sposervice cmdlet

    Reply
  • I am having this problem as well. In my case, I have two versions installed. Is this causing a conflict? I’ve tried to remove all versions, but the 16.0.20414.0 can’t be removed and might have been installed by other means other than Install-Module.

    Name Version
    —- ——-
    Microsoft.Online.SharePoint.PowerShell 16.0.20414.12000
    Microsoft.Online.SharePoint.PowerShell 16.0.20414.0

    Reply
  • Same here
    import-module : Could not load type ‘Microsoft.SharePoint.Client.Publishing.PortalLaunch.PortalLaunchRedirectionType’ from assembly ‘Microsoft.SharePoint.Client.Publishing, Version=16.0.0.0, Culture=neutral,
    PublicKeyToken=71e9bce111e9429c’.
    At line:1 char:1
    + import-module microsoft.online.sharepoint.powershell
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Import-Module], TypeLoadException
    + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand

    Reply
  • I have tried all the above steps that the problem still exists.

    Reply

Leave a Reply

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