cannot connect to exchange online via powershell

Anonymous
2020-06-24T16:23:06+00:00

I am unable to access exchange online via powershell anymore. it has been about 2 or 3 months since i have tried but this used to work with no issues. 

I have tried connecting 3 ways, all of which fail with the same error

#1

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession -Session $Session -DisableNameChecking

the progress bar comes up, it says importing and counts up to 6 or 700 commands as expected then the unexpected error message:

Import-PSSession : Data returned by the remote Get-FormatData command is not in the expected format.

After that, none of the commands work - example Get-Mailbox 

#2

Connect-EXOPSSession -UserPrincipalName ******@x.com

same deal. same error

Import-PSSession : Data returned by the remote Get-FormatData command is not in the expected format.

At C:\Users\x\AppData\Local\Apps\2.0\A53V0WOT.PE1\6Y7OL9NA.H46\micr..tion_1f16bd4ec4c2bb19_0010.0000_673f37

c317fb5976\CreateExoPSSession.ps1:311 char:40

  • ...      $PSSessionModuleInfo = Import-PSSession $PSSession -AllowClobber

+                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidResult: (:) [Import-PSSession], ArgumentException

    + FullyQualifiedErrorId : ErrorMalformedDataFromRemoteCommand,Microsoft.PowerShell.Commands.ImportPSSessionCommand

#3

Connect-ExchangeOnline -UserPrincipalName ******@x.com -ShowProgress $true

same deal. same error

The module allows access to all existing remote PowerShell (V1) cmdlets in addition to the 9 new, faster, and more reliable cmdlets.

|--------------------------------------------------------------------------|

|    Old Cmdlets                    |    New/Reliable/Faster Cmdlets       |

|--------------------------------------------------------------------------|

|    Get-CASMailbox                 |    Get-EXOCASMailbox                 |

|    Get-Mailbox                    |    Get-EXOMailbox                    |

|    Get-MailboxFolderPermission    |    Get-EXOMailboxFolderPermission    |

|    Get-MailboxFolderStatistics    |    Get-EXOMailboxFolderStatistics    |

|    Get-MailboxPermission          |    Get-EXOMailboxPermission          |

|    Get-MailboxStatistics          |    Get-EXOMailboxStatistics          |

|    Get-MobileDeviceStatistics     |    Get-EXOMobileDeviceStatistics     |

|    Get-Recipient                  |    Get-EXORecipient                  |

|    Get-RecipientPermission        |    Get-EXORecipientPermission        |

|--------------------------------------------------------------------------|

To get additional information, run: Get-Help Connect-ExchangeOnline or check https://aka.ms/exops-docs

Send your product improvement suggestions and feedback to ******@service.microsoft.com. For issues related to the module, contact Microsoft support. Don't use the feedback alias for problems or support issues.


Import-PSSession : Data returned by the remote Get-FormatData command is not in the expected format.

At C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\1.0.1\ExchangeOnlineManagement.psm1:454 char:40

  • ... oduleInfo = Import-PSSession $PSSession -AllowClobber -DisableNameChe ...

+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidResult: (:) [Import-PSSession], ArgumentException

    + FullyQualifiedErrorId : ErrorMalformedDataFromRemoteCommand,Microsoft.PowerShell.Commands.ImportPSSessionCommand

At this point effectively unable to admin exchange online via powershell. Anyone have any ideas?

Microsoft 365 and Office | Subscription, account, billing | For business | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

87 answers

Sort by: Newest
  1. Anonymous
    2020-06-27T15:45:43+00:00

    This morning had this issue as well, after years of success (including a couple days ago with the basic

    Set-ExecutionPolicy RemoteSigned

    $UserCredential = Get-Credential

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

    Import-PSSession $Session

    I also have a few other services associated with the above batch

    connect-msolservice -Credential $UserCredential

    connect-AzureAD -Credential $UserCredential 

    Received the error 

    Import-PSSession : Data returned by the remote Get-FormatData command is not in the expected format.

    For the Exchange portion. 

    The Exchange Online commands fail. 

    MSOL and AzureAD runs fine. 

    However, I have had success running the same commands against another tenant I have access to.

    So definitively something going on with 365 infrastructure (considering how issues are miraculously correcting themselves after a couple of days). 

    Update: 

    After a review of the thread, I noticed a comment re the new 

    Connect-ExchangeOnline

    Installed per 

    https://docs.microsoft.com/en-us/powershell/exchange/exchange-online-powershell-v2?view=exchange-ps

    and this resolved the connectivity to the initial tenant. 

    I will try the 'old way' in a couple of days just to see if it corrects itself.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2020-06-27T03:00:11+00:00

    I have the same error today,

    I tried even in PowerShell Core, and It is the same error importing the PSSession, since I needed some emergency access, I couldn't wait, so I did the following:

    1. Created a Session with basic Authentication,

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $UserCredential -Authentication Basic -AllowRedir

    ection

    1. Once session is opened, then run

    Enter-PSSession $session

    and Voila,

    It won't give you the best experience though, but if you need to get in, you have it.

    Was this answer helpful?

    6 people found this answer helpful.
    0 comments No comments
  3. Anonymous
    2020-06-26T14:24:19+00:00

    The issue has finally cleared up for me this morning, two days after it began. I didn't do or change anything. My account is cloud-only, not on premises.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2020-06-26T14:23:21+00:00

    I have been running the same script for years and this behavior started couples of days ago. Odd enough, I run the exact same script in different PS threads using 4 different accounts (on prem accounts). I always get the same issue from a thread using the exact same account… not against the three others. Could that be a coincidence?

    May I also mention that before it fails and get this « Import-PSSession : Data returned by the remote Get-FormatData command is not in the expected format» error, my script (which re instantiate multiple times) got through the “import-pssession” one time or two before the error pops up. So the error is not consistent on my side.

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2020-06-26T13:47:09+00:00

    Had the same problem for more than a week. In my case I managed to solve it by switching the connection from a cloud only user account to a on-prem AD User synced to O365. 

    Maybe this will help everyone else. 

    I am also using an account synced from on prem (and always have) but get this error.

    Was this answer helpful?

    0 comments No comments