Exchange PowerShell MFA v2 with Certificate Failing

David Jenkins 946 Reputation points
2020-08-23T18:59:49.59+00:00

I'm trying to connect to exchange using the v2 powershell module. Logging in with regular user accounts works fine. I ensured I upgraded to the preview edition so I could use apps and certificates for powershell automation. I've got a self signed cert and imported it to the app. When I try to connect I get the following error:

Using ConnectionUri:'https://outlook.office365.com/powershell-liveid/', in the environment:'O365Default'.
New-ExoPSSession : Connecting to remote server outlook.office365.com failed with the following error message : ᨰ緱ɋ For
more information, see the about_Remote_Troubleshooting Help topic.
At C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\2.0.3\ExchangeOnlineManagement.psm1:481 char:30

  • ... PSSession = New-ExoPSSession -ExchangeEnvironmentName $ExchangeEnviro ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : ResourceUnavailable: (:) [New-ExoPSSession], PSRemotingTransportException
  • FullyQualifiedErrorId : System.Management.Automation.Remoting.PSRemotingDataStructureException,Microsoft.Exchang
    e.Management.ExoPowershellSnapin.NewExoPSSession
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,204 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,638 questions
0 comments No comments
{count} votes

6 additional answers

Sort by: Most helpful
  1. Andy David - MVP 142.3K Reputation points MVP
    2020-08-23T19:03:34.087+00:00

    You want to use this to connect:

    Connect-ExchangeOnline

    Example:

    Connect-ExchangeOnline -CertificateFilePath "C:\Users\johndoe\Desktop\automation-cert.pfx" -CertificatePassword (ConvertTo-SecureString -String "<My Password>" -AsPlainText -Force) -AppID "36ee4c6c-0812-40a2-b820-b22ebd02bce3" -Organization "contosoelectronics.onmicrosoft.com"

    https://techcommunity.microsoft.com/t5/exchange-team-blog/modern-auth-and-unattended-scripts-in-exchange-online-powershell/ba-p/1497387

    0 comments No comments

  2. David Jenkins 946 Reputation points
    2020-08-23T23:44:44.56+00:00

    Same error.

    Perhaps its a provisioning thing. I created the app today.

    0 comments No comments

  3. Joyce Shen - MSFT 16,646 Reputation points
    2020-08-24T01:58:31.133+00:00

    That may be the cause, please also ensure you have met all the prerequisites to perform the action.

    For example make sure you have setup/register the app in Azure correctly.

    Detailed steps and information can be seen in below link:

    A first look at Certificate-Based Authentication for Exchange Online Remote PowerShell


    If the response is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments

  4. Vasil Michev 95,836 Reputation points MVP
    2020-08-24T06:17:29.64+00:00

    Make sure you have granted a qualifying Azure AD role for the application object, such as Global Admin/Exchange admin.

    0 comments No comments