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

%3CLINGO-SUB%20id%3D%22lingo-sub-2370286%22%20slang%3D%22en-US%22%3EThe%20'Connect-SPOService'%20command%20was%20found%20in%20the%20module%2C%20but%20the%20module%20could%20not%20be%20loaded.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2370286%22%20slang%3D%22en-US%22%3E%3CP%3EI%20need%20to%20use%20Microsoft.SharePoint.Client.dll%20and%20Microsoft.SharePoint.Client.Runtime.dll%20to%20load%20and%20query%20SharePoint%20lists.%20First%20I%20need%20to%20Connect-SPOService.%20Before%20I%20install%20the%20client%20components%26nbsp%3B%20(sharepointclientcomponents_16-6906-1200_x64-en-us.msi)%20Connect-SPOService%20command%20works%20fine.%20After%20client%20components%20install%2C%20I%20get%20an%20error%20message%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EConnect-SPOService%20%3A%20The%20'Connect-SPOService'%20command%20was%20found%20in%20the%20module%20'Microsoft.Online.SharePoint.PowerShell'%2C%20but%20the%20module%20could%20not%20be%20loaded.%20For%20more%3CBR%20%2F%3Einformation%2C%20run%20'Import-Module%20Microsoft.Online.SharePoint.PowerShell'.%3CBR%20%2F%3EAt%20line%3A1%20char%3A1%3CBR%20%2F%3E%2B%20Connect-SPOService%20-Url%20%3CA%20href%3D%22https%3A%2F%2Faligngeneral-admin.sharepoint.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2F%3CCOMPANY%3E-admin.sharepoint.com%2F%3C%2FCOMPANY%3E%3C%2FA%3E%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20ObjectNotFound%3A%20(Connect-SPOService%3AString)%20%5B%5D%2C%20CommandNotFoundException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20CouldNotAutoloadMatchingModule%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%26nbsp%3Brun%20'Import-Module%20Microsoft.Online.SharePoint.PowerShell'%20as%20the%20message%20suggests%20and%20this%20error%20comes%20up%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EImport-Module%20%3A%20Could%20not%20load%20type%20'Microsoft.SharePoint.Administration.DesignPackageType'%20from%20assembly%20'Microsoft.SharePoint.Client%2C%20Version%3D16.0.0.0%2C%3CBR%20%2F%3ECulture%3Dneutral%2C%20PublicKeyToken%3D71e9bce111e9429c'.%3CBR%20%2F%3EAt%20line%3A1%20char%3A1%3CBR%20%2F%3E%2B%20Import-Module%20Microsoft.Online.SharePoint.PowerShell%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20NotSpecified%3A%20(%3A)%20%5BImport-Module%5D%2C%20TypeLoadException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20System.TypeLoadException%2CMicrosoft.PowerShell.Commands.ImportModuleCommand%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20follow%20these%20steps%2C%20but%20it%20just%20keeps%20me%20in%20a%20loop%20of%20uninstalling%26nbsp%3Band%20reinstalling%20SharePoint%20shell%20and%20the%20client%20libraries.%26nbsp%3B%3C%2FP%3E%3CP%3E1.%20Open%20Control%20Panel%20-%26gt%3B%20UnInstall%20Programs%20-%26gt%3B%20Search%20for%20SharePoint%20related%20setups.%3CBR%20%2F%3E2.%20Locate%20SharePoint%20Client%20Components%20-%26gt%3B%20Uninstall.%3CBR%20%2F%3E3.%20Locate%20SharePoint%20Online%20Management%20Shell%20-%26gt%3B%20Uninstall.%3CBR%20%2F%3E4.%20Ensure%20that%20anyone%20of%20the%20above%20setup%20is%20installed%20more%20than%20one%20time.%20If%20so%2C%20remove%20all%20the%20instances.%3CBR%20%2F%3E5.%20Now%2C%20open%20the%20Powershell%20console%20in%20administrative%20mode%20(Run%20as%20administrator).%3CBR%20%2F%3E6.%20Uninstall%20SPO%20Powershell%20module%20(If%20already%20exists)%20by%20running%20this%20command%3A%20Uninstall-Module%20-Name%20Microsoft.Online.SharePoint.PowerShell%20-AllVersions%20-Force%3CBR%20%2F%3E7.%20Finally%2C%20install%20the%20latest%20SPO%20Powershell%20module%20by%20running%20this%20command%3A%20Install-Module%20Microsoft.Online.SharePoint.PowerShell%20-Force%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhy%20installing%20client%20components%20seems%20to%20break%20the%20Connect-SPOService%20and%20how%20do%20I%20fix%20it%3F%3C%2FP%3E%3CP%3EMy%20PowerShell%20version%3A%26nbsp%3B5.1.19041.906%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EEdit%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EWhen%20I%20Set-PSDebug%20-trace%202%2C%20I%20get%20this%20output.%20I'm%20not%20sure%20where%20to%20take%20it%20from%20here.%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22t_bara_0-1621614329420.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F282682i40BEE5FFEFB31D19%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22t_bara_0-1621614329420.png%22%20alt%3D%22t_bara_0-1621614329420.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2370286%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2578403%22%20slang%3D%22en-US%22%3ERe%3A%20The%20'Connect-SPOService'%20command%20was%20found%20in%20the%20module%2C%20but%20the%20module%20could%20not%20be%20loaded.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2578403%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1058326%22%20target%3D%22_blank%22%3E%40t_bara%3C%2FA%3E%26nbsp%3BI'm%20running%20into%20the%20exact%20same%20issue.%20Did%20you%20find%20a%20solution%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Regular Visitor

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

 

1 Reply

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