connection to exchange online from powershell is declining suddenly

Mark Villa 41 Reputation points
2022-11-18T22:29:31.977+00:00

Hi,

We encountered a problem that we are not able to connect to exchange from powershell anymore, It's connects normally from another account so the problem isn't from machine, it in the account. It was fine before yesterday, Today I wake up suddenly to find this error:

New-PSSession : [ps.outlook.com] Connecting to remote server ps.outlook.com failed with the following error message :
Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:12

  • $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin
    gTransportException
  • FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailed

I've tried many solution in the internet with no results: security defaults are disabled, Basic Auth enabled for all protocols.

I use this commands for connection:

$LiveCred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
Import-PSSession $Session

I Need Help Urgently Please.
Thanks in advance

Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,350 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,364 questions
{count} votes

Accepted answer
  1. Aholic Liang-MSFT 13,741 Reputation points Microsoft Vendor
    2022-11-21T04:55:28.933+00:00

    Hi @Mark Villa ,
    Are you still using the v1 version of the PowerShell module? When Basic auth for Exchange Online has been turned off, it would stop working. According to the error, it is an expected behavior.
    Understanding the Different Versions of Exchange Online PowerShell Modules and Basic Auth - Microsoft Community Hub
    262374-2022-11-21-1.png
    It recommended that you could refer to the follow steps to use the latest v3 module to connect to Exchange online.

    1. Refer to the link to upgrade Powershell to the latest version:Installing PowerShell on Windows - PowerShell | Microsoft Learn
    2. Follow this link to update Exchange PowerShell module: About the Exchange Online PowerShell V2 module and V3 module | Microsoft Learn
    3. After the update is complete, you can refer to the command link below to connect to Exchange online PowerShell : Connect-ExchangeOnline -UserPrincipalName navin@Company portal .onmicrosoft.com

    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 additional answer

Sort by: Most helpful
  1. Vasil Michev 95,341 Reputation points MVP
    2022-11-19T09:04:35.547+00:00

    The method you are using is decade old by now, update your scripts. And make sure you are using modern auth, as legacy methods are now blocked. Using the V3 module will let you bypass all these issues: https://learn.microsoft.com/en-us/powershell/exchange/exchange-online-powershell-v2?view=exchange-ps#install-and-maintain-the-exchange-online-powershell-module

    1 person found this answer helpful.
    0 comments No comments