question

ABBA-2380 avatar image
1 Vote"
ABBA-2380 asked soerennielsen commented

powershell login error

hi all
i am new to powershell and azure world. i am trying to login to my office365 azure using powershell. my admin account is MFA enabled. i am using connect-azuread command. i get the prompt to enter username/password and then approve the request using authenticator. but after approval from authenticator app i always get the error
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


can you anyone please help me with this. what am i doing wrong here.

regards

windows-server-powershellazure-ad-connect
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@ABBA-2380 can you confirm the PowerShell version, this error indicates that the module you are trying to use .net core and does not have a System.Security.Cryptography.SHA256Cng class. This works perfectly fine with mine powershell 5.1
can you check with the same version ?

You can check the version using $PSVersionTable

64306-image.png


0 Votes 0 ·
image.png (19.5 KiB)

i am using version 7

64979-image.png


0 Votes 0 ·
image.png (15.6 KiB)

@ABBA-2380 Seems to be an issue with .netframework used in this module. check this for more reference.


0 Votes 0 ·
Show more comments
michev avatar image
6 Votes"
michev answered MohamedSoliman-0118 commented

If you are running this on PowerShell 7+/Core, you need to import the module in compatibility mode:

 Import-Module AzureAD -UseWindowsPowerShell
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

i am using version 7. i installed and imported the module and still getting the same error. 65036-image.png


0 Votes 0 ·
image.png (3.6 KiB)

And did you try using the -UseWindowsPowerShell as suggested above?

0 Votes 0 ·

yes. i did. i am getting an error when using this command

66038-image.png


5 Votes 5 ·
image.png (9.5 KiB)

Thanks it worked for me on my localmachine , but it's doesn't work when uploading the script to aws " lambda function" it shows the same error

{
"errorType": "FileNotFoundException",
"errorMessage": "Could not load file or assembly 'System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.\n",
"stackTrace": [
"at Amazon.Lambda.PowerShellHost.PowerShellFunctionHost.ExecuteFunction(Stream inputStream, ILambdaContext context)",
"at lambda_method(Closure , Stream , Stream , LambdaContextInternal )"
]
}

0 Votes 0 ·
Owen-Murr avatar image
0 Votes"
Owen-Murr answered SrenLauritsNielsen-3335 commented

This should no longer need the -usewindowspowershell.

Which version of the AzureAD module do you have installed, and have you updated to the latest stable version of Powershell core/7?

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Neither works :-(

My versions are: AzureAD 2.0.2.130, PowerShell 7.1.3, windows 10.

ARGH! I have to invite 150 users by hand here.

0 Votes 0 ·
Owen-Murr avatar image Owen-Murr SrenLauritsNielsen-3335 ·

You may have to do it through Powershell 5.1 for this to work and get around the error message.

I will have a look at my install tomorrow with an MFA enabled account and update this post.

EDIT.

I have just tested this on my machine, I am adamant that I had this working but I am getting the same error as yourself.

Using @michev fix works for me.

81184-image.png

Try that again, if not use Powershell 5.1.

For further reading take a look at the Microsoft Graph Module.


0 Votes 0 ·
image.png (18.4 KiB)
DilgamSharifov-2314 avatar image
1 Vote"
DilgamSharifov-2314 answered DanielNeagu-2924 commented

Thank you, it worked for me with "Import-Module AzureAD -UseWindowsPowerShell" in VS Studio.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

how did you excute the command in VS Studio?

0 Votes 0 ·
CarrTaliaferro-2068 avatar image
0 Votes"
CarrTaliaferro-2068 answered soerennielsen commented

If I may piggyback here? I am getting the same error stream, most likely for the same reasons. But IDK anything about this, other than what I see in the MSFT docs: Use PS 5.

I have the latest PS 7 installed. How do I "use PS5"?

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,

In VS code in your powershell 7.x.x terminal window you can just type "powershell.exe -version 5.1" to load that version.

0 Votes 0 ·

Well yes.

"Powershell.exe" wíll load the latest version of powershell before core´, so 5.x.

Pwsh.exe will load the core version, so version 7.x.


Doesn't matter from which shell you do it.

0 Votes 0 ·