Are you using PowerShell 7? That object type isn't supported by .Net Core.
powershell connect to o365
HI!
When i run the following comand to connect o office 365 by powershell i get the error bellow.
It's been a while since i use ps to connect to o365 can anyone help me with what is missing?
Import-Module MSOnline
$TenantUname="user"
$TenantPass = ConvertTo-SecureString "pass" -AsPlainText -Force
$TenantCredentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $TenantUname, $TenantPass
Connect-MsolService -Credential $TenantCredentials
Error:
Connect-MsolService: Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Windows for business Windows Server User experience PowerShell
3 answers
Sort by: Most helpful
-
-
Limitless Technology 39,916 Reputation points
2022-02-16T15:41:14.777+00:00 Hello @Tiago Oliveira
I would recommend to check which version of Powershell you are using by running $PSVersionTable in Powershell.
If you are running version 7, you may need to install and update the AzureAD module to work succesfully. Run the next from elevated Powershell window:
Install-Module AzureAD
Import-Module AzureAD -UseWindowsPowerShellHope this helps with your query,
--
--If the reply is helpful, please Upvote and Accept as answer-- -
Tiago Oliveira 1 Reputation point
2022-02-17T12:54:32.777+00:00 Hi!
i fixed the script by changing it to the following
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Import-Module MSOnline -UseWindowsPowerShell
$TenantUname="user"
$TenantPass = ConvertTo-SecureString "pass" -AsPlainText -Force
$TenantCredentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $TenantUname, $TenantPass
Connect-MsolService -Credential $TenantCredentials