after importing AzureAd module and Calling the Connect-AzureAd Cmdlet
an interactive form opens to supply credentials and provide MFA authentication
Install-Module -Name "AzureAD" -Verbose -Force -AllowClobber
Import-Module -Name "AzureAD" -Verbose -Force
Get-Module -Name "AzureAD"-ListAvailable | Select-object Name, Version
Connect-AzureAD
The Connect-AzureAd Cmdlet should continue successfully and establish a connection with Azure AD
connect-azuread : One or more errors occurred. (Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.): Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
At line:1 char:1
+ connect-azuread
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], AadAuthenticationFailedException
+ FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
connect-azuread : One or more errors occurred. (Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.)
At line:1 char:1
+ connect-azuread
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], AggregateException
+ FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
connect-azuread : Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
At line:1 char:1
+ connect-azuread
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], TypeLoadException
+ FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
connect-azuread : One or more errors occurred. (Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.): Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
At line:1 char:1
+ connect-azuread
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-AzureAD], AadAuthenticationFailedException
+ FullyQualifiedErrorId : Microsoft.Open.Azure.AD.CommonLibrary.AadAuthenticationFailedException,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
Name Value
---- -----
PSVersion 7.0.0-preview.3
PSEdition Core
GitCommitId 7.0.0-preview.3
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
@aollivierre Please move the issue to Azure feedback site.
Perhaps it is here https://feedback.azure.com/forums/169401-azure-active-directory
This issue has been marked as external and has not had any activity for 1 day. It has been be closed for housekeeping purposes.
I don't get why this is moved to the azure feedback site. I am encountering this exact same error on the 7-Preview. Here is my version info:
powershell
Name Value
---- -----
PSVersion 7.0.0-preview.5
PSEdition Core
GitCommitId 7.0.0-preview.5
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Works fine with Desktop 5.1 on my current windows 10 build.
@toddwseattle We need a simply repo to discover a root of the issue. Azure site is good place to start.
/cc @SteveL-MSFT
@SteveL-MSFT Same problem; apparently I'm on preview.5 now. Repro Steps
````powershell
C:\Windows\System32>Update-Module -Name AzureAD
C:\Windows\System32> Import-Module -Name AzureAD
C:\Windows\System32> Get-Module -Name "AzureAD" -ListAvailable | Select-Object Name,Version
Name Version
---- -------
AzureAD 2.0.2.61
AzureAD 2.0.2.52
C:\Windows\System32> Connect-AzureAD
Connect-AzureAD: One or more errors occurred. (Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.): Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Connect-AzureAD: One or more errors occurred. (Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.)
Connect-AzureAD: Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Connect-AzureAD: One or more errors occurred. (Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.): Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Here is my version info right now:
powershell
Name Value
---- -----
PSVersion 7.0.0-preview.5
PSEdition Core
GitCommitId 7.0.0-preview.5
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
````
I'm logging in with my Office365 admin / AzureAD address that has 2 factor auth. The popup comes up; i enter the password and text code; and then I get the errors.
What else do you need?
@toddwseattle please see https://github.com/PowerShell/PowerShell/issues/11070
I was having issues connecting to the SFB module as well when using the v7 but was unable to connect properly. After switching my VS Code's shell to the regular 5.1 I was able to login properly to that service.
Exactly the same behaviours as @O365scripts
Noted this to when attempting to connect to O365. Posted a question to https://docs.microsoft.com/en-us/office365/enterprise/powershell/connect-to-office-365-powershell#connect-with-the-microsoft-azure-active-directory-module-for-windows-powershell, and the related GitHub, but as noted in that issue, is looks like PS Core is not support for AzureAD or the Msol named CmdLets.
I guess there is not much that can by done until Azure Az catches up.
Summary: Connect to your Office 365 organization using Office 365 PowerShell to perform admin center tasks from the command line.
Got error when run command:
Connect-AzureAD
Connect-AzureAD: One or more errors occurred. (Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.): Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Sorry, Screen shot is not allowed to attach. Add attachment here should be a cool feature.
The PowerShell is version 7.
This happens when I use command
$Credential = Get-Credential
Connect-AzureAD -Credential $Credential
I'm getting this error too - fresh install of PowerShell on osx.
Name Value
---- -----
PSVersion 7.0.0
PSEdition Core
GitCommitId 7.0.0
OS Darwin 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan 9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
This happens when I use command
$Credential = Get-Credential
Connect-AzureAD -Credential $Credential
I am having the same problem when running this command
Same problem.
Tried with AzureAD and AzureADPreview
get-module -ListAvailable Azure*
Directory: C:\Users\user\OneDrive\Documents\PowerShell\Modules
ModuleType Version PreRelease Name PSEdition ExportedCommands
---------- ------- ---------- ---- --------- ----------------
Binary 2.0.2.85 AzureADPreview Desk
import-module AzureADPreview
Connect-AzureAD
Connect-AzureAD: One or more errors occurred. (Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.): Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
In short, it's not supported in .NET Core, and therefore not in PowerShell Core (7.X).
Thanks,
New Microsoft Graph PS module is looking very promising.
Hope, documentation will be ready soon and we continue with user creation process. Right now for the New-MgUser we have this :)
Get-Help New-MgUser -Examples
NAME
New-MgUser
SYNOPSIS
Add new entity to users
-------------------------- EXAMPLE 1 --------------------------
PS C:\>{{ Add code here }}
{{ Add output here }}
-------------------------- EXAMPLE 2 --------------------------
PS C:\>{{ Add code here }}
{{ Add output here }}
Note that partial support is available using the following preview package: https://www.poshtestgallery.com/packages/AzureAD.Standard.Preview/0.1.599.7
Register-PackageSource -Name PoshTestGallery -Location https://www.poshtestgallery.com/api/v2/ -ProviderName PowerShellGet
Install-Module -Name AzureAD.Standard.Preview -Repository PoshTestGallery
Azure Active Directory .NetStandard Preview Module. This is a Private Preview release of Azure Active Directory .NetStandard Module, available in PSGallery Internal only.
@ohadschn I tried your steps but issue is still not resolved. My machine is Windows 10. t already had Powershell 5.1. But today I installed Core based 7.x latest release of Powershell. I am using 7.x ISE of PS to run AZ module command and so it asked for Azure login and faced same error.
Hi, @hmahajanHM
Try this
Install-Module Microsoft.Graph
Connect-Graph
Get-MgUser | select -First 5
It works in my PS7.0 There is no instruction how to create a new user, but getting existing is fine.
@hmahajanHM most likely you already had incorrect PS assemblies loaded onto the ISE process. I suggest you start a new regular PowerShell terminal process (Start Menu -> PowerShell) and try again.
@ohadschn I tried your steps but issue is still not resolved. My machine is Windows 10. t already had Powershell 5.1. But today I installed Core based 7.x latest release of Powershell. I am using 7.x ISE of PS to run AZ module command and so it asked for Azure login and faced same error.
Hi, I am having the same issue and I am installing on 64-bit.Did you find the solution?
As posted above I have the same thing happening. 7.0 power-shell core causes the same error to take place.
Using power-shell 5.1 things seem to work just fine.
Same as what JeretSB said. 7.0.2. fails. 5.1 works.
Use: Import-Module AzureAD -UseWindowsPowerShell
Until Azure Active Directory product group makes the AzureAD module compatible with PowerShell 7, we need to use the Windows PowerShell Compatibility feature. You can find more details at https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_windows_powershell_compatibility?view=powershell-7
Thanks to @alexandair
about_Windows_PowerShell_Compatibility - PowerShell
@SteveL-MSFT is there a place the AzureAD team has a uservoice or something so we can ask them for the code change described in https://github.com/dotnet/runtime/issues/25044?
@JustinGrote couldn't find one I would suggest starting in Azure PowerShell repo and maybe they can help redirect
You could instead try to use the az rest invoking the graph api.
Until the time az-cli is in par with the AzureAD powershell module you can instead use the graph api
az login --tenant <tenantname.onmicrosoft.com>
$uri = "https://graph.microsoft.com/v1.0/applications"
$allApplications = az rest `
--method GET `
--uri $uri `
--headers 'Content-Type=application/json' | convertfrom-json
$allApplications.value |% {"{0}-{1}" -f $_.appid, $_.displayname}
I have put some samples using az rest here,
https://github.com/joepaulk/utilities/blob/master/manage-azuread-applicationregistrations.ps1
You may also refer to: https://damienbod.com/2020/06/22/using-azure-cli-to-create-azure-app-registrations/ from where i picked up inspiration
Other reference, how az rest use the accesstokens from az cli can be found here,
https://mikhail.io/2019/07/how-azure-cli-manages-access-tokens/
Most helpful comment
In short, it's not supported in .NET Core, and therefore not in PowerShell Core (7.X).