SOLVED

Connect-SPOService: Could not load type 'System.Security.Cryptography.SHA256Cng' .....

%3CLINGO-SUB%20id%3D%22lingo-sub-1982745%22%20slang%3D%22en-US%22%3EConnect-SPOService%3A%20Could%20not%20load%20type%20'System.Security.Cryptography.SHA256Cng'%20.....%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1982745%22%20slang%3D%22en-US%22%3E%3CP%3EMu%20environment%3A%3C%2FP%3E%3CP%3EWindows%2010%3C%2FP%3E%3CP%3Einstalled%20PowerShell%207.1%3C%2FP%3E%3CP%3ERunning%20Microsoft%20Sharepoint%20Online%20command%20%22connect-SPOService%22%20using%20elevated%20session%20does%20not%20work%20when%20running%20PowerShell%207.1%2C%20but%20does%20work%20when%20running%20Windows%20PowerShell%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDoes%20anyone%20know%20why%20the%20connect-SPOService%20wouls%20not%20run%20on%20PWSH%207.1%3F%20I%20installed%20this%20core%20version%20because%20I%20read%20everywhere%20(as%20well%20as%20in%20training%20videos)%20that%20one%20should%20not%20use%20Windows%20PowerShell.%20But%2C%20to%20my%20frustration%2C%20the%20cmdlet%20'Connect-SPOService'%20does%20not%20run%20on%20PWSH%207.1%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1982745%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3E.Net%20Core%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1982801%22%20slang%3D%22en-US%22%3ERe%3A%20Connect-SPOService%3A%20Could%20not%20load%20type%20'System.Security.Cryptography.SHA256Cng'%20.....%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1982801%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20module%20is%20not%20supported%20on%20PSCore%2F7.1%2C%20it%20has%20dependencies%20on%20.Net%20libraries%20which%20are%20not%20supported%20there.%20It%20should%20run%20fun%20in%20compatibility%20mode%20though%20(use%20the%20%3CEM%3EUseWindowsPowerShell%3C%2FEM%3E%3CSPAN%3E%26nbsp%3Bswitch%20with%20Import-Module%3C%2FSPAN%3E).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1984918%22%20slang%3D%22en-US%22%3ERe%3A%20Connect-SPOService%3A%20Could%20not%20load%20type%20'System.Security.Cryptography.SHA256Cng'%20.....%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1984918%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F58%22%20target%3D%22_blank%22%3E%40Vasil%20Michev%3C%2FA%3E%26nbsp%3Bthank%20you%20for%20your%20clear%20answer!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EInteresting%20fact%3A%20I%20was%20following%20advice%20in%20an%20e-book%20for%20PowerShell%20beginners%2C%20where%20I%20followed%20every%20step%20of%20the%20given%20advice%3B%20the%26nbsp%3B%20e-book%20clearly%20indicated%20that%20one%20should%20use%20PWS%207.1.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20I%20really%20hope%20that%20your%20reply%20will%20be%20read%20by%20many%20other%20PWS%20starters!!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Mu environment:

Windows 10

installed PowerShell 7.1

Running Microsoft Sharepoint Online command "connect-SPOService" using elevated session does not work when running PowerShell 7.1, but does work when running Windows PowerShell

 

Does anyone know why the connect-SPOService wouls not run on PWSH 7.1? I installed this core version because I read everywhere (as well as in training videos) that one should not use Windows PowerShell. But, to my frustration, the cmdlet 'Connect-SPOService' does not run on PWSH 7.1

4 Replies
best response confirmed by Bernd_Kroon (Occasional Contributor)
Solution

The module is not supported on PSCore/7.1, it has dependencies on .Net libraries which are not supported there. It should run fun in compatibility mode though (use the UseWindowsPowerShell switch with Import-Module).

 

 

@Vasil Michev thank you for your clear answer!

 

Interesting fact: I was following advice in an e-book for PowerShell beginners, where I followed every step of the given advice; the  e-book clearly indicated that one should use PWS 7.1.

 

So I really hope that your reply will be read by many other PWS starters!!

 

 

@Bernd_Kroon 

This is a challenge. Since PowerShell 7.1 uses .NET 5, cmdlets/modules you run must work against that version of .NET Core. There are some older modules that work fine in Pwsh 7.1, but many do not. With 7.0, the team built a compatibility mechanism into Import-Module which crates a remoting session to the local host connecting to a WIndows PowerShell remoting configuration. Then, it loads the module into the remote session and then uses implicit remoting to create local functions you can then use.

 

So if you use Install-WIndowsFeature, then, the module is loaded in a compatibility session and you see local functions.  About the only downside is that the Format XML is not carried forward, but you can fix that manually by importing the XML file from the module's folder

 

But Some modules do not load properly - such as Best Practices. Three modules are blocked from being loaded via a JSON file in the pwsh $home folder. And some modules appear to work but don't. And finally, a few modules,  like updates services (with WSUS) do not work at all via PowerShell 7 - use WIndows PowerShell for those scripts

 

@Thomas Lee Dear Thomas, thank you for the added detail and clarification.

 

Reviewing what I now understand, I reach the conclusion that PWS 7.1 is really not fit for purpose: to be a suitable follow up for Microsoft PowerShell 5.1. 

PWS 7.1 has advantages and may be the way forward (due to multiplatform capability), but it realy does not qualify as a replacement yet as long as it does not work 'out-of-the-box' for SPO or PnP sharepoint online modules. It does allow to use the MicrosoftTeams module, but that is not enough to replace a graphical interface if you want to customize a clients Teams + SharePoint environment.

 

I would welcome if the PowerShell Community would make clarifications like the one given by Tomas  about the limitation of PWS 7 clear and easy to find for everyone who starts using PowerShell. It took me many, many hours to understand why all the magic did not work!