Can't import SharePoint online Powershell module

%3CLINGO-SUB%20id%3D%22lingo-sub-359630%22%20slang%3D%22en-US%22%3ERe%3A%20Can't%20import%20SharePoint%20online%20Powershell%20module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-359630%22%20slang%3D%22en-US%22%3ESome%20things%20you%20can%20try%3A%3CBR%20%2F%3E(1)%20Check%20If%20you%20already%20installed%20the%20module%20by%20means%20of%20the%20SharePoint%20Online%20Management%20Shell...if%20so%2C%20uninstall%20it%3CBR%20%2F%3E(2)%20Try%20to%20us%20the%20-force%20parameter%20in%20the%20Import-Module%20cmdlet%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-871594%22%20slang%3D%22en-US%22%3ERe%3A%20Can't%20import%20SharePoint%20online%20Powershell%20module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-871594%22%20slang%3D%22en-US%22%3EI%20had%20the%20exact%20same%20problem%2C%20mine%20was%20caused%20by%20Microsoft.SharePoint.Client.dll%20installed%20in%20the%20Global%20Assembly%20Cache.%3CBR%20%2F%3E%3CBR%20%2F%3ETo%20resolve%20the%20issue%2C%3CBR%20%2F%3E(1)%20Navigate%20to%20C%3A%5CWindows%5CMicrosoft.NET%5Cassembly%5CGAC_MSIL%3CBR%20%2F%3E(2)%20Remove%20the%20Microsoft.SharePoint.*%20assemblies%3CBR%20%2F%3E(3)%20Uninstall%20the%20module%20with%20Uninstall-Module%20-Name%20Microsoft.Online.SharePoint.PowerShell%3CBR%20%2F%3E%3CBR%20%2F%3EAfter%20reinstalling%20the%20module%20from%20the%20PowerShell%20gallery%2C%20the%20module%20worked%20flawlessly.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1079551%22%20slang%3D%22en-US%22%3ERe%3A%20Can't%20import%20SharePoint%20online%20Powershell%20module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1079551%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3BI%20just%20found%20this%20thread%20because%20I%20was%20having%20the%20same%20problem%20-%20thank%20you%20for%20these%20instructions%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F212869%22%20target%3D%22_blank%22%3E%40Glenn%20Goffin%3C%2FA%3E%2C%20they%20did%20the%20trick%20for%20me!%26nbsp%3B%3CIMG%20class%3D%22lia-deferred-image%20lia-image-emoji%22%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Fhtml%2Fimages%2Femoticons%2Fsmile_40x40.gif%22%20alt%3D%22%3Asmile%3A%22%20title%3D%22%3Asmile%3A%22%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1104436%22%20slang%3D%22en-US%22%3ERe%3A%20Can't%20import%20SharePoint%20online%20Powershell%20module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1104436%22%20slang%3D%22en-US%22%3E%3CP%3EThx%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F212869%22%20target%3D%22_blank%22%3E%40Glenn%20Goffin%3C%2FA%3E%26nbsp%3B%2C%20this%20one%20worked%20for%20me%20!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-359581%22%20slang%3D%22en-US%22%3ECan't%20import%20SharePoint%20online%20Powershell%20module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-359581%22%20slang%3D%22en-US%22%3E%3CP%3Ewhen%20I%20use%3CBR%20%2F%3EImport-Module%20Microsoft.Online.SharePoint.PowerShell%3C%2FP%3E%3CP%3Eit%20says%3C%2FP%3E%3CP%3EPS%20C%3A%5CWindows%5Csystem32%26gt%3B%20Import-Module%20Microsoft.Online.SharePoint.PowerShell%3CBR%20%2F%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%20Culture%3Dneutral%2C%3CBR%20%2F%3EPublicKeyToken%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%20have%20this%20binary%20module%20installed%3A%3C%2FP%3E%3CP%3EDirectory%3A%20C%3A%5CProgram%20Files%5CWindowsPowerShell%5CModules%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EModuleType%20Version%20Name%20ExportedCommands%3CBR%20%2F%3E----------%20-------%20----%20----------------%3CBR%20%2F%3EBinary%2016.0.86...%20Microsoft.Online.SharePoint.Powe...%3CBR%20%2F%3EBinary%2016.0.80...%20Microsoft.Online.SharePoint.Powe...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20clues%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-359581%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1178159%22%20slang%3D%22en-US%22%3ERe%3A%20Can't%20import%20SharePoint%20online%20Powershell%20module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1178159%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F212869%22%20target%3D%22_blank%22%3E%40Glenn%20Goffin%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20very%20same%20error%2Fissue%20trying%20to%20load%20on%20a%20SharePoint%202019%20server.%26nbsp%3B%20I%20don't%20think%20it%20would%20be%20a%20good%20idea%20to%20delete%20all%20the%20Microsoft.SharePoint%20assemblies%20from%20this%20server.%26nbsp%3B%20%26nbsp%3BAny%20ideas%20if%20it%20will%20corrupt%20the%20SharePoint%20installation%3F%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1268618%22%20slang%3D%22en-US%22%3ERe%3A%20Can't%20import%20SharePoint%20online%20Powershell%20module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1268618%22%20slang%3D%22en-US%22%3EThanks%20for%20your%20help!%20It%20worked%20for%20me.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1279062%22%20slang%3D%22en-US%22%3ERe%3A%20Can't%20import%20SharePoint%20online%20Powershell%20module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1279062%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F212869%22%20target%3D%22_blank%22%3E%40Glenn%20Goffin%3C%2FA%3E%26nbsp%3B%3CSPAN%3EThanks%20for%20your%20help!%20It%20worked%20for%20me.%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3EWhat%20are%26nbsp%3B%3CSPAN%3Ethose%20assemblies%20for%20in%20C%3A%5CWindows%5CMicrosoft.NET%5Cassembly%5CGAC_MSIL%20%3F%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1329433%22%20slang%3D%22en-US%22%3ERe%3A%20Can't%20import%20SharePoint%20online%20Powershell%20module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1329433%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F212869%22%20target%3D%22_blank%22%3E%40Glenn%20Goffin%3C%2FA%3E%26nbsp%3BI%20don't%20think%20direct%20manipulation%20of%20dlls%20in%20the%20GAC%20is%20the%20right%20solution%20here.%20This%20issue%20is%20actually%20caused%20by%20a%20conflict%20with%20%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-ca%2Fdownload%2Fdetails.aspx%3Fid%3D42038%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESharePoint%20Online%20Components%20SDK%3C%2FA%3E.%20Recent%20versions%20of%20the%20Microsoft.Online.SharePoint.PowerShell%20module%20simply%20will%20not%20load%20as%20long%20as%20that%20is%20installed%20on%20a%20system.%20If%20you%20uninstall%20SharePoint%20Online%20Components%2C%20the%20module%20will%20load%20just%20fine.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1382363%22%20slang%3D%22en-US%22%3ERe%3A%20Can't%20import%20SharePoint%20online%20Powershell%20module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1382363%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F35784%22%20target%3D%22_blank%22%3E%40Allison%20Bates%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ewould%20be%20also%20very%20interesting%20for%20me%20whether%20%22clearing%22%20the%20GAC%20destroys%20SharePoint%20Server%20installation.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1587996%22%20slang%3D%22en-US%22%3ERe%3A%20Can't%20import%20SharePoint%20online%20Powershell%20module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1587996%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F11537%22%20target%3D%22_blank%22%3E%40Kirk%20Munro%3C%2FA%3E%26nbsp%3Balthough%20I%20strongly%20agree%20with%20your%20cautious%20approach%20to%20this%2C%20I%20wanted%20to%20note%20that%20my%20various%20attempts%20to%20uninstall%20the%20SharePoint%20Online%20Components%20(e.g.%20initial%20uninstall%20%3D%20no%20luck.%26nbsp%3B%20re-install%20and%20uninstall%20using%20elevated%20command%20prompt%20%3D%20no%20luck)%20never%20did%20the%20trick.%26nbsp%3B%20Using%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F142376%22%20target%3D%22_blank%22%3E%40Glenn%20Goffin%3C%2FA%3E%26nbsp%3B's%20GAC%20%22nuclear%20option%22%20was%20what%20finally%20did%20the%20trick%20for%20me.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20assume%20the%20SOC%20components%20came%20in%20from%20my%20Visual%20Studio%202019%20install%20since%20I%20don't%20know%20how%20else%20they%20got%20installed%2C%20btw.%26nbsp%3B%20But%20for%20now%2C%20adios%20SOC%2FCOSM%20dlls.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%2C%20Kirk%2C%20your%20warnings%20may%20be%20especially%20important%20for%20those%20(unlike%20me)%20who%20are%20doing%20ShPt%20dev%20work.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERespectfully%2C%20D.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1602780%22%20slang%3D%22en-US%22%3ERe%3A%20Can't%20import%20SharePoint%20online%20Powershell%20module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1602780%22%20slang%3D%22en-US%22%3EThank%20you%20worked.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1723768%22%20slang%3D%22en-US%22%3ERe%3A%20Can't%20import%20SharePoint%20online%20Powershell%20module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1723768%22%20slang%3D%22en-US%22%3E%3CP%3EManual%20removing%20CSOM%20assemblies%20from%20the%20GAC%20is%20not%20a%20good%20idea%20-%20especially%20if%20you%20have%20SP%20on-prem%20running%20on%20the%20same%20server.%20Problem%20is%20caused%20by%20several%20instances%20of%20SPO%20SDKs%20and%20may%20be%20solved%20this%20way%3A%3C%2FP%3E%0A%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%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1750984%22%20slang%3D%22en-US%22%3ERe%3A%20Can't%20import%20SharePoint%20online%20Powershell%20module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1750984%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%20so%20much%20for%20your%20post.%20It%20has%20just%20worked%20for%20me%20after%20a%20lot%20of%20getting%20annoyed%20at%20powershell!%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F212869%22%20target%3D%22_blank%22%3E%40Glenn%20Goffin%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1858556%22%20slang%3D%22en-US%22%3ERe%3A%20Can't%20import%20SharePoint%20online%20Powershell%20module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1858556%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F150496%22%20target%3D%22_blank%22%3E%40Alexey%20Sadomov%3C%2FA%3E%26nbsp%3Bthese%20steps%20worked%20for%20me.%20Thanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

when I use
Import-Module Microsoft.Online.SharePoint.PowerShell

it says

PS C:\Windows\system32> Import-Module Microsoft.Online.SharePoint.PowerShell
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 have this binary module installed:

Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Binary 16.0.86... Microsoft.Online.SharePoint.Powe...
Binary 16.0.80... Microsoft.Online.SharePoint.Powe...

 

Any clues?

14 Replies
Highlighted
Some things you can try:
(1) Check If you already installed the module by means of the SharePoint Online Management Shell...if so, uninstall it
(2) Try to us the -force parameter in the Import-Module cmdlet
Highlighted
I had the exact same problem, mine was caused by Microsoft.SharePoint.Client.dll installed in the Global Assembly Cache.

To resolve the issue,
(1) Navigate to C:\Windows\Microsoft.NET\assembly\GAC_MSIL
(2) Remove the Microsoft.SharePoint.* assemblies
(3) Uninstall the module with Uninstall-Module -Name Microsoft.Online.SharePoint.PowerShell

After reinstalling the module from the PowerShell gallery, the module worked flawlessly.


Highlighted

 I just found this thread because I was having the same problem - thank you for these instructions @Glenn Goffin, they did the trick for me! :smile:

Thx @Glenn Goffin , this one worked for me !

Highlighted

@Glenn Goffin 

 

I have very same error/issue trying to load on a SharePoint 2019 server.  I don't think it would be a good idea to delete all the Microsoft.SharePoint assemblies from this server.   Any ideas if it will corrupt the SharePoint installation? 

Highlighted
Thanks for your help! It worked for me.
Highlighted

@Glenn Goffin Thanks for your help! It worked for me.

What are those assemblies for in C:\Windows\Microsoft.NET\assembly\GAC_MSIL ?

Highlighted

@Glenn Goffin I don't think direct manipulation of dlls in the GAC is the right solution here. This issue is actually caused by a conflict with SharePoint Online Components SDK. Recent versions of the Microsoft.Online.SharePoint.PowerShell module simply will not load as long as that is installed on a system. If you uninstall SharePoint Online Components, the module will load just fine.

Highlighted

@Allison Bates 

would be also very interesting for me whether "clearing" the GAC destroys SharePoint Server installation.

Highlighted

@Kirk Munro although I strongly agree with your cautious approach to this, I wanted to note that my various attempts to uninstall the SharePoint Online Components (e.g. initial uninstall = no luck.  re-install and uninstall using elevated command prompt = no luck) never did the trick.  Using @Glenn Goffin 's GAC "nuclear option" was what finally did the trick for me.

 

I assume the SOC components came in from my Visual Studio 2019 install since I don't know how else they got installed, btw.  But for now, adios SOC/COSM dlls.

 

So, Kirk, your warnings may be especially important for those (unlike me) who are doing ShPt dev work.

 

Respectfully, D.

Highlighted
Thank you worked.
Highlighted

Manual removing CSOM assemblies from the GAC is not a good idea - especially if you have SP on-prem running on the same server. Problem is caused by several instances of SPO SDKs and may be solved this way:

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

Highlighted

Thank you so much for your post. It has just worked for me after a lot of getting annoyed at powershell!
@Glenn Goffin 

Highlighted

@Alexey Sadomov these steps worked for me. Thanks!