Sync Public Folders to Exchange online fails Unable to create a remote shell session to Exchange Online. The error is as follows: "Connecting to remote server outlook.office365.com failed with the following error message : Access is denied.

Thomas Walters 21 Reputation points
2021-09-30T12:06:27.55+00:00

I am performing an Exchange 2013 to Office365 Migration. I am at the point where I need to make on-prem public folders visible to Office365 mailboxes. I am attempting to run the script sync-modernmailpublicfolders.ps1 per guidance provided here: https://learn.microsoft.com/en-us/exchange/hybrid-deployment/set-up-modern-hybrid-public-folders. Running the script returns:
InitializeExchangeOnlineRemoteSession : Unable to create a remote shell session to Exchange Online. The error is as
follows: "Connecting to remote server outlook.office365.com failed with the following error message : Access is
denied. For more information, see the about_Remote_Troubleshooting Help topic.".
At C:\script\Sync-ModernMailPublicFolders.ps1:506 char:5

  • InitializeExchangeOnlineRemoteSession;
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
  • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,InitializeExchangeOnlineRemoteSession

The account being used is has the Office 365 Global Administrator and Exchange Online Organization Management roles assigned. The account does not require MFA. In the same powershell session I can "connect-ExchangeOnline" without issue, so I'm thinking the error message may be misleading or bogus. I've run this script many times in the past in other organizations and never had a problem. On-Prem Exchange 2013 CU23 is patched to within thirty days. I have run the script on different Exchange servers, always with the same result. I have tried running the script in the EMS and in Windows Powershell. All powershell on Exchange servers reports same powershell version:
PS C:\script> $psversiontable

Name Value


PSVersion 5.1.14409.1018
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1018
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

I have opened a support call with Microsoft, but am not getting anywhere. I'm hoping someone out there has run into this one.

TIA
Tom

Microsoft Exchange Hybrid Management
Microsoft Exchange Hybrid Management
Microsoft Exchange: Microsoft messaging and collaboration software.Hybrid Management: Organizing, handling, directing or controlling hybrid deployments.
1,884 questions
{count} votes

Accepted answer
  1. Ben Krause 76 Reputation points
    2021-10-09T11:23:18.847+00:00

    I'm thinking it has to do with not supporting Modern Authentication and "I THINK" that Microsoft is starting to phase out basic authentication. I need to test this myself but here's a discussion on github that talks about it and a potential workaround.

    https://github.com/MicrosoftDocs/OfficeDocs-Exchange/issues/1563


6 additional answers

Sort by: Most helpful
  1. Ben Krause 76 Reputation points
    2021-10-07T19:32:27.403+00:00

    I too am having this issue.
    Exchange 2016 setup with Hybrid Simple Configuration with Office 365
    I was able to migrate a test mailbox to Office 365 from on-premises. Once that was done the O365 mailbox cannot access the Public Folders on-site.
    Until we can get this fixed we cannot migrate to Office 365 fully.
    I had Conditional Access requiring MFA for all users but I made an exception for my account. My account has full admin access to Office 365.
    I verified that the account did not have MFA "Enforced" on the individual account
    The Azure Security defaults are off
    Under the "Modern Authentication" section of Settings>Org Settings, I had "Allow access to basic authentication protocols" unchecked for Exchange Online PowerShell originally but then checked it so that it will allow access and it still does not work. Maybe I have to wait for that setting to apply?
    Regardless, I can try tomorrow but below is the output I get too.

    [PS] C:\pfscripts>.\Sync-ModernMailPublicFolders.ps1 -Credential (Get-Credential) -CsvSummaryFile:c:\pfscripts\sync_summ
    
    
    cmdlet Get-Credential at command pipeline position 1
    Supply values for the following parameters:
    Credential
    [10/7/2021 2:46:19 PM] Creating an Exchange Online remote session...
    InitializeExchangeOnlineRemoteSession : Unable to create a remote shell session to Exchange Online. The error is as
    follows: "Connecting to remote server outlook.office365.com failed with the following error message : Access is
    denied. For more information, see the about_Remote_Troubleshooting Help topic.".
    At C:\pfscripts\Sync-ModernMailPublicFolders.ps1:506 char:5
    +     InitializeExchangeOnlineRemoteSession;
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
        + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,InitializeExchangeOnlineRemoteSession
    
    0 comments No comments

  2. 79237859 1 Reputation point
    2021-11-03T15:17:57.447+00:00

    Anyone ever get this to work? I am facing the same issue.