ruudmens / LazyAdmin

SysAdmin scripts for you to use.
MIT License
606 stars 216 forks source link

Could not load type 'System.Security.Cryptography.SHA256Cng' #5

Closed TBSJordanNash closed 2 years ago

TBSJordanNash commented 2 years ago

When running in PowerShell 7, the MSOnline module must be loaded using compatibility mode (-UseWindowsPowerShell) or it will fail:

Line | 126 | Connect-MsolService | ~~~~~~~ | Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, | PublicKeyToken=b77a5c561934e089'.

TBSJordanNash commented 2 years ago

$psversiontable

Name Value


PSVersion 7.2.2 PSEdition Core GitCommitId 7.2.2 OS Microsoft Windows 10.0.22000 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0

ruudmens commented 2 years ago

I have updated the scripts with the following check:

if ($Host.Version.Major -eq 7) { Import-Module MSOnline -UseWindowsPowershell } Connect-MsolService