Connect-SPOService : No valid OAuth 2.0 authentication session exists ?

EnterpriseArchitect 5,516 Reputation points
2023-02-20T02:47:20.1466667+00:00

How to fix the issue to connect to SharePoint Online using PowerShell like below?

Because when I am using the PowerShell ISE, and then the command:

Connect-SPOService -Url 'https://CompanyName-admin.sharepoint.com'

I got the error:

Connect-SPOService : No valid OAuth 2.0 authentication session exists At line:1 char:1

Screenshot 2023-02-20 134108

Thank you.

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,399 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,003 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,626 questions
SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,972 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,707 questions
{count} vote

Accepted answer
  1. Jessie Sanchez 96 Reputation points
    2024-03-29T00:01:00.54+00:00
    Import-Module Microsoft.Online.SharePoint.PowerShell -UseWindowsPowerShell
    
    Connect-SPOService -url https://***-admin.sharepoint.com 
    (DO NOT USE "-Credential")
    
    4 people found this answer helpful.

4 additional answers

Sort by: Most helpful
  1. Dineshkumar Jothi 10 Reputation points
    2023-09-07T12:54:00.93+00:00

    Please check the URL Connect-SPOService only accept sharepoint Admin site URL not site collection URL.

    2 people found this answer helpful.
    0 comments No comments

  2. MagicHappenZ 26 Reputation points
    2024-03-05T16:08:47.1066667+00:00

    2024 and the module still does not support browser authentication making it pretty much useless to companies that use FIDO2 keys...

    2 people found this answer helpful.
    0 comments No comments

  3. RaytheonXie_MSFT 37,151 Reputation points Microsoft Vendor
    2023-02-20T07:47:09.0833333+00:00

    Hi @EnterpriseArchitect ,

    Per my test, we will get a windows to log in like following picture after call the cmdlet, and your browser doesn't support this function.

    User's image

    This error means you need to update your browser or download Edge as default browser. As a workaround, you can also use following cmdlet without log with a window. We can write the user account and secret into the cmdlet. Please make a reference

    $username = "admin@contoso.sharepoint.com" 
    $password = "password" 
    $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force) 
    Connect-SPOService -Url https://contoso-admin.sharepoint.com -Credential $cred
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  4. Marlon Christ 5 Reputation points
    2024-04-12T13:24:30.2733333+00:00

    After I set Microsoft Edge as default browser again, microsoft login window opened up as normal.
    Thanks!

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.