Fix: “Connect-SPOService: No valid OAuth 2.0 authentication session exists” Error
Problem:
When trying to connect to SharePoint Online through PowerShell 7, got this error message “Connect-SPOService: No valid OAuth 2.0 authentication session exists”.
Solution:
Use the “-UseWindowsPowerShell” switch to import the PowerShell Module for SharePoint Online, when you use PowerShell 7!
Import-Module Microsoft.Online.SharePoint.PowerShell -UseWindowsPowerShell
The same error message “No valid OAuth 2.0 authentication session exists” appears if the environment is in ITAR. Make sure to add -Region ITAR when running Connect-SPOService.
Example: Connect-SPOService -url “https://salaudeen-admin.sharepoint.com” -Region ITAR
where https://salaudeen-admin.sharepoint.com is the admin URL of an ITAR tenant
It doesn’t work on the inbuilt Windows 10 PowerShell version 5. You can check the version by using this command.
$PSVersiontable
The “-UseWindowsPowerShell” does work if you install PowershellVersion 7 and then make sure you are using the correct version becasue they will install side by side.
“C:\Program Files\PowerShell\7\pwsh.exe”
I still get the error though!
Connect-SPOService: No valid OAuth 2.0 authentication session exists
I’m not sure, there may be a tanant setting that needs to be changed.
I do have MFA enforced
Doesnt work.
there is no module called Usewindowspowershell
This applies only to PowerShell 7!