Connect-AzAccount does not work in PowerShell Integrated Console
Note, the solution is posted in the Azure PowerShell module. They have a temporary engineering built of the Az.Accounts module, with version 2.6.2 with instructions on how to install. The link is here: https://github.com/Azure/azure-powershell/issues/16340
Prerequisites
- [X] I have written a descriptive issue title.
- [X] I have searched all issues to ensure it has not already been reported.
- [X] I have read the troubleshooting guide.
- [X] I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
Summary
I have setup VS Code on 2 new computers and they are both having the same issue. I have the Integrated PowerShell Console set to load Windows PowerShell 5.1. When I run a script, the PowerShell Integrated Console (PIC) gives the error shown below. Even if I type the Connect-AzAccount manually in the PIC I get the same error. However, if I switch the terminal to Windows PowerShell (not Integrated), the command works fine (it loads the login prompt in an external PowerShell window). But when I run any script it automatically switches back to the PIC. Note that PowerShell Core works fine, it loads the login prompt in a browser window.
I have one older computer running Windows 10 that has had VS Code configured for years that is not showing the problem. I tried copying all the settings in the %appdata%, but it did not solve the problem.
Error:
WARNING: Unable to acquire token for tenant 'organizations' with error 'Method 'GetTokenAsync' in type 'Azure.Identity.InteractiveBrowserCredential' from assembly 'Azure.Identity, Version=1.4.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' does not have an implementation.'
Connect-AzAccount : Method 'GetTokenAsync' in type 'Azure.Identity.InteractiveBrowserCredential' from assembly 'Azure.Identity, Version=1.4.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' does not have an
implementation.
At line:1 char:1
- Connect-AzAccount
-
+ CategoryInfo : CloseError: (:) [Connect-AzAccount], TypeLoadException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand
PowerShell Version
Name Value
---- -----
PSVersion 5.1.22000.282
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22000.282
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Visual Studio Code Version
1.61.2
6cba118ac49a1b88332f312a8f67186f7f3c1643
x64
Extension Version
[email protected]
Steps to Reproduce
Install VS Code Install PowerShell Az modules (Install-Module -Name Az) Set the default console to be Windows PowerShell 5.1 so that the PowerShell Integrated Console runs with Windows PowerShell. Type the command in the PowerShell Integrated Console window or put the command in a script and run: Connect-AzAccount
Visuals


Logs
Does this reproduce with PowerShell 7? If not, it's likely a GAC-dependency issue like several others where the error is "method not found" and unfortunately may not be resolvable within the constraints of PowerShell 5.1.
It does work with PowerShell 7. Unfortunately, I have some Windows forms built into the PowerShell scripts so I can't use PowerShell 7. It is working on 2 other Windows 10 computers that I had installed VS Code back in 2019, which is running VS Code version 1.61.1. I can't figure out why the old ones work and the new installs don't work. I tried new installs on both Windows 10 and Windows 11, with current version of VS Code and version 1.60.x, everything fails. It only fails in the Integrated console, not the regular console. Is there any settings somewhere other than in $AppData%\Code?
Are your old installations using an old version of the extension? My guess is dependencies were updated and now we have a dependency which conflicts with that module. Unfortunately in Windows PowerShell the GAC prevents us from isolating those dependencies (which we successfully do in PowerShell Core).
Unfortunately, I have some Windows forms built into the PowerShell scripts so I can't use PowerShell 7.
The good news is that Windows Forms do work in PowerShell 7, and we even have a regression test about running code in the integrated console that utilizes Forms.
My recommendation would be to open a separate powershell.exe console in Code that is not the integrated console, which will isolate you away from any interference caused by the editor services being loaded in that instance.
The old machines are running PowerShell extension v2021.10.1 and VS Code 1.16.1. They are working fine with the integrated console. I am not sure what you mean by "open a powershell.exe console in Code that is not the integrated console". When I debug, I have VS Code start a new temporary console in order to reload my classes. It always starts the PowerShell Integrated Console. Even if I turn that off, if I am in the PowerShell terminal that works, as soon as I run my script it switches to the integrated console to run.
Good news about PowerShell Core 7 that I didn't know, I thought it was a generic shell and would only support things that run on all platforms (linux, mac, windows). I also found an extension for Visual Studio 2019 that will run my scripts in PowerShell 5.1. I like the interface for VS Code better though, I use color schemes for various messages in my scripts and VS2019 doesn't show colors when debugging.
Debugging in VS Code will always use the integrated console, there's no way around that, as the editor services are required for debugging (that library is what hooks up the VS Code Debugger to the PowerShell debugger). Can you run your script in PowerShell Core, or is Windows PowerShell a hard requirement for you?
Windows PowerShell is a hard requirement right now. The scripts are run by several users and having them install and maintain PowerShell Core would be an issue. I also have several "using" statements at the top, which reference modules in subfolders of the application. It works great in Windows PowerShell and I can copy the scripts to multiple locations and they just work. No need to install and update modules, just a copy/paste installation. But this method doesn't work with PowerShell Core, it complains that it can't find the modules. I haven't looked too deep into it though.
Example: using module ..\CWPSModules\LocalFunctions using module ..\CWPSModules\WindowsFormControls using module ..\CWPSModules\WindowsFormFunctions
might be a bad design, but it makes updates and portability a lot quicker and easier. I just copy it to a central repository and everyone runs it from there, with no local modules needing updating. If you have any suggestions for improvement, I am always open to better ideas.
Windows PowerShell is a hard requirement right now.
Oof, well I'm sorry about that. I'll see if we can figure out which dependencies are conflicting, though still not sure if it'll be fixable. One of the modules would (most likely) need to change its dependent version to match the other, and then go through a release, and then it'll work until they diverge again. And that's assuming that is indeed the issue.
Ok between #3645 and reports on the PowerShell Discord, I am quite sure this is indeed the problem!
If someone can figure out which dependency now conflicts between PSES and Az.Accounts (which I'm pretty sure is actually going to be from their update to Azure.Core to v1.20.0), then we can update it and fix this for you, at least for a while 😅
Same problem here
Hi, we have same problem here on the last update of vsc.
Connect-AzAccount : Method 'GetTokenAsync' in type 'Azure.Identity.InteractiveBrowserCredential' from assembly 'Azure.Identity, Version=1.4.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8'
does not have an implementation.
I found a workarround that is open a new powershell window (not integrated console) , but we cannot debug for example till this get solved.
If i can provide any information to help solve the problem pls update me, thanks!
br
Ok between #3645 and reports on the PowerShell Discord, I am quite sure this is indeed the problem!
If someone can figure out which dependency now conflicts between PSES and Az.Accounts (which I'm pretty sure is actually going to be from their update to Azure.Core to v1.20.0), then we can update it and fix this for you, at least for a while 😅
If someone can figure this out, we can bandage this temporarily. But we're up against .NET Framework constraints with this kind of bug. Maybe loop in the Azure module devs?
Same problem here. It started when Az.Accounts was updated to 2.6.0. Running Connect-AzAccount in PS7 in VSCode terminal works, also running the command in PowerShell 5.1 (outside of VSCode) works.
Same here, this used to work fine but not anymore, hopefully we can get this working in VSCode again soon.
EDIT: downgraded PowerShell Extension to 2021.2.2, so it does look to be VSCode itself related.
so it does look to be VSCode itself related
As I've said, there is a dependency conflict between the Az.Accounts module and PSES. I just don't know which dependency as there are a lot to sift through.
Would really appreciate it if one of you would file a bug at the Azure PowerShell module itself so we can start a conversation with their devs. I would also suggest testing their Az Preview module to check if it continues to repro.
Actually, you don't need to test their preview module. Both it and their stable module updated to 6.6.0 just two days. Please update and re-test!
I have updated the Azure PowerShell modules to 6.6.0 and am getting the same results. I have created an issue with the Azure PowerShell team, as noted above. The Az.Accounts is now at version 2.6.1
I have tested this on a new VM with fresh install and fail's out of the box, also on preview. If i downgrade VSC and powershell extension, still's the same.
Any workarround (downgrade) we can do to make it working till a fix goes out?
Thanks all and have a great day!
Hi, Had the same issue, and not sure but there is a workaround that worked for me at least. When you get the error message in VS Code: WARNING: Unable to acquire token for tenant 'organizations' with error 'Method 'GetTokenAsync' in type 'Azure.Identity.InteractiveBrowserCredential' from assembly 'Azure.Identity, Version=1.4.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' does not have an implementation.' Connect-AzAccount : Method 'GetTokenAsync' in type 'Azure.Identity.InteractiveBrowserCredential' from assembly 'Azure.Identity, Version=1.4.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' does no t have an implementation.
Just click 'New Terminal Window' and rerun. It worked for me.
