Forum Discussion

Bernd_Kroon's avatar
Bernd_Kroon
Brass Contributor
Dec 12, 2020

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

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

  • 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).

     

     

  • 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).

     

     

    • Bernd_Kroon's avatar
      Bernd_Kroon
      Brass Contributor

      VasilMichev 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!!

       

       

      • Thomas Lee's avatar
        Thomas Lee
        Brass Contributor

        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

         

Resources