The term ‘Connect-SPOService’ is not recognized

SharePoint PowerShell Module

We recently got contacted by a developer who was experiencing the following issue:

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.
At line:1 char:1
+ Connect-SPOService
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Connect-SPOService:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

The big challenge was that the Sharepoint PowerShell module was definitely installed on his system. This was confirmed by the following output:

PS C:\WINDOWS\system32> Get-Module -ListAvailable *sharepoint*


    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     16.0.21... Microsoft.Online.SharePoint.Powe...
Script     0.1.0      SharePointOnline.CSOM               {Load-SPOnlineCSOMAssembly, Load-SPOnlineCSOMAssemblies}
Binary     3.29.21... SharePointPnPPowerShellOnline       {Add-PnPAlert, Add-PnPApp, Add-PnPApplicationCustomizer, Add-PnPClientSidePage...}

(if you don’t have the Microsoft.Online.SharePoint.PowerShell module installed get it here)

As you see there are several SharePoint modules installed. But why is Connect-SPOService not working?

Notice something very odd in the above output? The module Microsoft.Online.SharePoint.PowerShell does not have any exported commands!

Different File Versions

This fact led me to investigate the consistency of .dll versions available on the system.

Use the following neat little PowerShell one-liner to list file versions. The path assumes you have installed the SharePoint PowerShell module with admin rights:

Get-ChildItem -Path 'C:\Program Files\WindowsPowerShell\Modules\Microsoft.Online.SharePoint.PowerShell\*Microsoft.SharePoint*.dll' -Recurse | ft Name,@{Label="Version";Expression={$_.VersionInfo.FileVersion}} -AutoSize

This should generate output similar to the following:

Name                                       Version
----                                       -------
Microsoft.SharePoint.Client.dll            16.0.21213.12000
Microsoft.SharePoint.Client.Publishing.dll 16.0.21213.12000
Microsoft.SharePoint.Client.Runtime.dll    16.0.21213.12000

Then search your system for mismatching .dll’s. In my case I found them in the Global Assembly Cache:

Get-ChildItem -Path C:\Windows\Microsoft.NET\assembly\GAC_MSIL\*Microsoft.SharePoint*.dll -Recurse | ft Name,@{Label="Version";Expression={$_.VersionInfo.FileVersion}} -AutoSize
Name Version ---- ------- Microsoft.SharePoint.Client.dll 16.0.21213.12000 Microsoft.SharePoint.Client.DocumentManagement.dll 16.0.6518.1200 Microsoft.SharePoint.Client.Publishing.dll 16.0.6518.1200 Microsoft.SharePoint.Client.Runtime.dll 16.0.21213.12000 Microsoft.SharePoint.Client.Search.dll 16.0.6518.1200 Microsoft.SharePoint.Client.Search.Applications.dll 16.0.6518.1200 Microsoft.SharePoint.Client.Taxonomy.dll 16.0.6518.1200 Microsoft.SharePoint.Client.UserProfiles.dll 16.0.6518.1200 Microsoft.SharePoint.WorkflowServices.Activities.dll 16.0.6518.1200

You’ll notice that two of our PowerShell dll’s check out fine but the third (Microsoft.SharePoint.Client.Publishing.dll) has different versions on my system:

  1. The PowerShell module has (the newer) version 16.0.21213.12000
  2. The Global Assembly Cache has (the older) version 16.0.6518.1200

To test if this is truly the culprit I removed Microsoft.SharePoint.Client.Publishing.dll from the Global Assembly Cache and tried to list my SharePoint PowerShell modules once more:

PS C:\WINDOWS\system32> Get-Module -ListAvailable *sharepoint*


    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     16.0.21... Microsoft.Online.SharePoint.Powe... {Register-SPODataEncryptionPolicy, Update-SPODataEncryptionPolicy, Get-SPODataEncryptionPolicy, Get-SPOSiteDataEncryptionPolicy...}
Script     0.1.0      SharePointOnline.CSOM               {Load-SPOnlineCSOMAssembly, Load-SPOnlineCSOMAssemblies}
Binary     3.29.21... SharePointPnPPowerShellOnline       {Add-PnPAlert, Add-PnPApp, Add-PnPApplicationCustomizer, Add-PnPClientSidePage...}

Bingo! As you see, commands are now found in the Microsoft.Online.SharePoint.PowerShell module. This is definitely a good sign 🙂

And as expected I’m now able to connect successfully to SharePoint Online:

PS C:\WINDOWS\system32> Connect-SPOService

cmdlet Connect-SPOService at command pipeline position 1
Supply values for the following parameters:
Url:

Summary

I hope this article was able to help you connect to SharePoint Online using the PowerShell module.

If you’re the type that likes to do your Office 365 administration as simple and efficiently as possible, please take a few minutes to check out Easy365Manager.

Easy365Manager is an affordable Office 365 extension to the Active Directory Users & Computers management console. With Easy365Manager you can manage your on-premises users and groups, Office 365 licenses and mailboxes in one single tool. Super easy!

Stop switching between multiple web consoles today. Download and install the fully functional 30 day trial. Most admins never look back…

Did you like this post? Maybe your friends will too!