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: Most helpful
  1. Anonymous
    2020-07-14T20:26:48+00:00

    Seems to me that you no longer need to load that into a session.  If I run the Connect-ExchangeOnline once it is done I appear to have access to the commands that need to execute.  All my nightly processes will execute tonight if I have issues I'll let you all know!

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2020-07-14T20:25:14+00:00

    THANK YOU!!!!!!!!!!!!!!!!!

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2020-07-14T20:17:40+00:00

    This is great Sandi! So I can just get rid of the Import-PSSession $Session line all together? 

    Funny, I had the -AllowClobber as well :) Such a funny name!

    Appreciate this context and the work you did!

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2020-07-14T19:29:35+00:00

    Thank you Friedrich!

    The correct connection line has WORKED!!!! (virtual round of applause).

    For everyone attached to this helpful thread, this was the line I used (additionally replacing the parameter -ConnectionUri when starting a new PSSession):

    Connect-ExchangeOnline -ConnectionUri "https://outlook.office365.com/powershell-liveid?SerializationLevel=Full" -Credential $UserCredential -ShowProgress $true

    #PS Session

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid?SerializationLevel=Full

    Hopefully this works for the majority of other users experiencing this hair pulling event log ;). It worked immediately once I run my runbook. Hopefully the issue can be isolated/resolved beyond the workaround.

    Thank you again Friedrich!

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2020-07-14T18:58:29+00:00

    Totally agree on a permanent solution.  I've changed my processes to use my personal account which has tenant admin/enterpise AD privs so things will keep working.  All my nightly processes run on a single server and I use an XML file to pull in the creds that the process will use when it runs.  I changed the XML cred file to store my credentials so all my process will pick up the changed cred file when it runs.  I store the XML file in the \Documents directory of the AD account that is running the process. 

    If it will help here is what I use to create the CredFile:

    $me = whoami

    $dir = "c:\users" + $me.Substring(($me.IndexOf("")+1),$me.length-($me.IndexOf("")+1)) + "\documents"

    $File = "my" + ($me.Substring(($me.IndexOf("")+1),$me.length-($me.IndexOf("")+1))).replace(".","") + "File.xml"

    $CredFile = $dir + $File

    Get-Credential | Export-Clixml $CredFile

    write-host "New Credential File Created for: " $me

    Here is the command to import that cred file:

    $LiveCred = Import-Clixml C:\Users&lt;UsrDirectory>\Documents\my<UsrAcct>File.xml

    Was this answer helpful?

    0 comments No comments