PowerShell/vscode-powershell

Unable to connect to Exchange Online

foss4ever opened this issue · 15 comments

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

I can't connect to Exchange Online from VS Code terminal.
Running command "connect-exchangeonline" I get the following error:

OperationStopped: Could not load file or assembly 'Microsoft.Identity.Client, Version=4.44.0.0, Culture=neutral, PublicKeyToken=03ae'.

The issue does not reproduce in standalone PowerShell terminal.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.3.1
PSEdition                      Core
GitCommitId                    7.3.1
OS                             Darwin 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct  9 20:14:54 PDT 2022; root:xnu-8792.41.9~2/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

Version: 1.74.3
Commit: 97dec172d3256f8ca4bfb2143f3f76b503ca0534
Date: 2023-01-09T17:07:18.579Z (1 wk ago)
Electron: 19.1.8
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Darwin x64 22.1.0
Sandboxed: No

Extension Version

The term 'code' is not recognized as a name of a cmdlet, function, script file, or executable program.

Steps to Reproduce

  1. Start terminal
  2. Run: sudo pwsh
  3. Run: Install-Module -Name ExchangeOnlineManagement
  4. Start VS Code
  5. Run: import-module ExchangeOnlineManagement
  6. Run: connect-exchangeOnline

Visuals

No response

Logs

No response

I have the same issue since I updated ExchangeOnlineManagement module.
I also installed the requested version for Microsoft.Identity.Client module, and uninstalled other versions.

Get-InstalledModule

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
3.1.0                ExchangeOnlineManagement            PSGallery            This is a General Availability (GA) release of the Exchange Online Powershell V3 module. Exchange Onl…
7.8.4                ImportExcel                         PSGallery            PowerShell module to import/export Excel spreadsheets, without Excel.…
4.44.0               Microsoft.Identity.Client           PSGallery            This package contains the binaries of the Microsoft Authentication Library for .NET (MSAL.NET).…
1.12.0               PnP.PowerShell                      PSGallery            Microsoft 365 Patterns and Practices PowerShell Cmdlets

Can you confirm that you can run the module as expected in a normal PowerShell terminal, that is, not in VS Code?

Yes, here you go:

image

ksl28 commented

I can confirm, that im seeing the same issue.
VScode: 1.74.2 (User setup)
Pwsh: 7.3.2

I need to share that the issue was solved, on my side, thanks to this finding from pttbr !
It occurs when using ExchangeOnlineManagement and PnP.PowerShell modules together.

Thank you @jerome-dl! That's...super interesting because the flip side of this issue is the same weird "it just doesn't work" with PnP.PowerShell #3510

I now have the same error coming up when attempting to connect to msonline in powershell terminal.

billede

I have you tried the workaround posted above?

I have you tried the workaround posted above?

What is the workaround exactly? It's not clear to me from the linked issue which mentions PnP.PowerSell, but I haven't ever used that module, so how does that enter the picture? Getting a bit confused here :)

A whole bunch of modules, like PnP.PowerShell and Exchange Online, rely on different (and conflicting) versions of some of the identity assemblies. The simplest workaround is to avoid loading any other module before trying Exchange Online, and that will likely work, but you need to check your profile or scripts you might be loading before using the module. Otherwise some people have had success altering the Exchange Online module manifest.

A whole bunch of modules, like PnP.PowerShell and Exchange Online, rely on different (and conflicting) versions of some of the identity assemblies. The simplest workaround is to avoid loading any other module before trying Exchange Online, and that will likely work, but you need to check your profile or scripts you might be loading before using the module. Otherwise some people have had success altering the Exchange Online module manifest.

That does in fact seem to work for the ExchangeOnlineManagement module, but not for the MSOnline module:

billede

I'm afraid the thing you mention about altering manifests is a little bit beyond my skills, as I am really just a sysadmin trying to get all the Office 365 related modules working in VSCode on MacOS, so that I no longer have to deal with this in my Windows VM ^_^

Oh, @foss4ever, your screenshot actually shows that you're not in the Extension Terminal, so your issue is directly with MSOnline. You're in a regular pwsh terminal (that happens to be in Code's Integrated terminal). Can you please open an issue with them?

This repository is specifically for issues with the PowerShell Extension, and so specifically the "PowerShell Extension" terminal, the one selected in this screenshot (it'll also have a "PowerShell Extension v2023.2.1" banner when it starts up):

Screenshot 2023-03-03 at 10 15 59 AM

If your issue occurs in one that just says "pwsh" not "PowerShell Extension" then it's not related to the code in this repo. I can still try to direct you to help, but it's not something I can solve.

In the article I linked (best thing I could find for "MSOnline") I would note that it says:

Please note that we will begin to deprecate this module when the functionality of this module is available in the newer Azure Active Directory PowerShell for Graph module. We advise customers who are creating new PowerShell scripts to use the newer module instead of this module.

So it's possible that module isn't even supported any more. Sorry! I hope you find a solution.

This issue has been marked as external. It has been automatically closed for housekeeping purposes.

@andschwa

I'm sorry for not getting back on this issue sooner, and for hassling you about a deprecated msonline module, but I do in fact get that very same error when attempting to connect-azuread in the PowerShell Extension terminal within VSCode:

image

Do I need to open a new issue for that?

@foss4ever not sure what's going on there, a lot that could be wrong. System.Windows.Forms is in .NET Core now, but I think maybe still Windows-only...it also looks like it could be a dependency conflict between it and another module. Please do open another issue!