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-09-21T09:11:43+00:00

    Any update on this?

    Hey everybody!

    it's been some time, sorry for the lack of updates on this.

    It's still very much an ongoing topic (and reports remain to be very valuable!).

    Expanding a bit on the problem with this issue and why it has been with us for this time:

    The symptoms occur at process level. It appears to start healthy, like any other instance of an EXO remoting endpoint and at some point develops the issues.

    The key problem is: Restarting it restores regular, healthy operation.

    This has a few consequences when it comes to troubleshooting:

    • Any targeted patch on an affected system will reset the machine to healthy, as a service restart is needed.
    • This makes it impossible to reasonably test-run any diagnostics improvements against a single instance
    • Thus, any such change needs to be rolled out globally, making it subject to our full update release cycle

    This has slowed the pace, but we have rolled out silent changes, waited for the next reports, analyzed more, etc. etc.

    It's not a glorious process, but work continues.

    It's just that until we manage to fully solve and fix this, you are unlikely to notice any changes.

    Sorry about the disruption and thank you for any patience you can muster,

    Friedrich

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2020-09-18T22:36:16+00:00

    Thanks Radtia! That works. I got our tenant name from our host this morning (as it turns out, not at all obvious for our company!) and I'm updating my scripts to use that format.

    Whew!

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2020-09-18T12:44:36+00:00

    Try this, it seems to work for me...without this "-DelegatedOrganization" switch, I cannot import the session as you are currently experiencing.

    Connect-ExchangeOnline -UserPrincipalName _______@______.___ -DelegatedOrganization TENANT.onmicrosoft.com

    good luck

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments
  4. Anonymous
    2020-09-18T02:25:32+00:00

    Failing for me, 2020-09-17, all syntaxes applied. Friedrich's form filled out. We're subscribed to Microsoft 365, and our people are in AzureAD. I'm not sure whether this thread is the answer to my issue, but the error messages are identical.

    All my scripts that used to work now get as far as "Creating implicit remoting module", a download, then fail at Import-PSSession $Session. $UserCredential = various forms of collecting credentials

    Old connection method that used to work but now fails

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

    Import-PSSession $Session

    Result:

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

    At nameofmyscript.ps1:6 char:1

    • Import-PSSession $Session
    • 
      

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

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

    +other failures due to the above failure

    Just prior to below, I installed PowerShellGet so I could install EXO V2 as per About the Exchange Online PowerShell V2 module so I can start connecting using non-basic authentication methods, in case that was part of the problem. Nope.

    I can't connect to Exchange Online PowerShell; although I can Import-Module ExchangeOnlineManagement in order to get to the point I can connect without MFA, Connect-ExchangeOnline -Credential $UserCredential -ShowProgress $true does the same "Creating implicit remoting module", a download, then consistently fails with the same error:

    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

    **Connect-ExchangeOnline -UserPrincipalName ****@mycompany.com -ShowProgress $true fails with

    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

    Connect-ExchangeOnline -ConnectionUri "https://outlook.office365.com/powershell-liveid?SerializationLevel=Full" fails with

    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

    For a guy who's just at the head end of learning PowerShell, this isn't as much fun as it looks. And as it turns out, I'm not learning it just for fun. This is preventing me from getting actual work done. :-(

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2020-09-17T12:45:14+00:00

    I am having the same issue. Using the -DelegatedOrg workaround listed up above worked, but this is an issue with many of the scripts we have running. Any update on this?

    Was this answer helpful?

    0 comments No comments