The 'Connect-SPOService' command was found in the module, but the module could not be loaded.

Copper Contributor

I need to use Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll to load and query SharePoint lists. First I need to Connect-SPOService. Before I install the client components  (sharepointclientcomponents_16-6906-1200_x64-en-us.msi) Connect-SPOService command works fine. After client components install, I get an error message:

 

Connect-SPOService : The 'Connect-SPOService' command was found in the module 'Microsoft.Online.SharePoint.PowerShell', but the module could not be loaded. For more
information, run 'Import-Module Microsoft.Online.SharePoint.PowerShell'.
At line:1 char:1
+ Connect-SPOService -Url https://<company>-admin.sharepoint.com/
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Connect-SPOService:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

 

I run 'Import-Module Microsoft.Online.SharePoint.PowerShell' as the message suggests and this error comes up:

 

Import-Module : Could not load type 'Microsoft.SharePoint.Administration.DesignPackageType' from assembly 'Microsoft.SharePoint.Client, 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

 

I follow these steps, but it just keeps me in a loop of uninstalling and reinstalling SharePoint shell and the client libraries. 

1. Open Control Panel -> UnInstall Programs -> Search for SharePoint related setups.
2. Locate SharePoint Client Components -> Uninstall.
3. Locate SharePoint Online Management Shell -> Uninstall.
4. Ensure that anyone of the above setup is installed more than one time. If so, remove all the instances.
5. Now, open the Powershell console in administrative mode (Run as administrator).
6. Uninstall SPO Powershell module (If already exists) by running this command: Uninstall-Module -Name Microsoft.Online.SharePoint.PowerShell -AllVersions -Force
7. Finally, install the latest SPO Powershell module by running this command: Install-Module Microsoft.Online.SharePoint.PowerShell -Force

 

Why installing client components seems to break the Connect-SPOService and how do I fix it?

My PowerShell version: 5.1.19041.906

 

Edit

When I Set-PSDebug -trace 2, I get this output. I'm not sure where to take it from here. 

t_bara_0-1621614329420.png

 

4 Replies

@t_bara I'm running into the exact same issue. Did you find a solution?

@LuckyLub @t_bara 

 

I'm in the same boat - the only difference being that my Powershell is later.  Has a solution been identified?? 

 

PS C:\Windows\system32> Install-Module Microsoft.Online.SharePoint.PowerShell -force
PS C:\Windows\system32> Connect-SPOService -Url https://eldertech-admin.sharepoint.com -credential icook@eldertech.com.au
Connect-SPOService : The 'Connect-SPOService' command was found in the module
'Microsoft.Online.SharePoint.PowerShell', but the module could not be loaded. For more information, run 'Import-Module
Microsoft.Online.SharePoint.PowerShell'.
At line:1 char:1
+ Connect-SPOService -Url https://eldertech-admin.sharepoint.com -crede ...
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Connect-SPOService:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

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

Name Version
---- -------
Microsoft.Online.SharePoint.PowerShell 16.0.21909.12000
Microsoft.Online.SharePoint.PowerShell 16.0.21811.12000

Hello, Do you have client components too?

"There is a known issue between the SharePoint Online Management Shell module and SharePoint Client Components SDK where the module will fail to load if both are installed on the same computer. If you encounter this issue, uninstall the SharePoint Client Components SDK."


https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-online/connect-sharepoint-online