azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Connect-AzAccount: The term 'Connect-AzAccount' is not recognized as a name of a cmdlet

Open Davidh-claranet opened this issue 2 years ago • 7 comments

Description

Hello The Connect-AzAccount is correctly recognized :

PS /> [root@server user]# docker run  -it mcr.microsoft.com/azure-powershell
PowerShell 7.2.4
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS /> Connect-AzAccount
WARNING: Interactive authentication is not supported in this session, please run cmdlet 'Connect-AzAccount -UseDeviceAuthentication'.
PS />

But when using http_proxy, https_proxy, HTTP_PROXY and HTTPS_PROXY environment variables, the Connect-AzAccount is no more recognized :

PS /> [root@server Z98D8008export HTTPS_PROXY=http://my_proxy:3128
[root@server user]# export HTTPS_PROXY=http://my_proxy:3128
[root@server user]# export HTTP_PROXY=http://my_proxy:3128
[root@server user]# export http_proxy=http://my_proxy:3128
[root@server user]# export https_proxy=http://my_proxy:3128
[root@server user]# docker run  -e http_proxy  -e https_proxy -e HTTP_PROXY -e HTTPS_PROXY -it mcr.microsoft.com/azure-powershe
ll
PowerShell 7.2.4
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS /> Connect-AzAccount                 
Connect-AzAccount: The term 'Connect-AzAccount' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

The Az.accounts module does not export commands :

PS /> get-module

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.8.0                 Az.Accounts
Manifest   7.0.0.0               Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty…}
Manifest   7.0.0.0               Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object…}      
Script     2.1.0                 PSReadLine                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler…}

Issue script & Debug output

PS /> $DebugPreference='Continue' 
PS /> import-module -name Az.Accounts
DEBUG: Registering Az shared AssemblyLoadContext for path: '/usr/local/share/powershell/Modules/Az.Accounts/2.8.0/StartupScripts/../AzSharedAlcAssemblies'.
DEBUG: AssemblyLoadContext registered.
Import-Module: An item with the same key has already been added. Key: https_proxy

Environment data

PS /> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.4
PSEdition                      Core
GitCommitId                    7.2.4
OS                             Linux 4.18.0-372.9.1.el8.x86_64 #1 SMP Fri Apr 15 22:12:19 EDT 2022
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

PS /> Get-Module Az*

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.8.0                 Az.Accounts

Error output

PS /> Resolve-AzError
Resolve-AzError: The term 'Resolve-AzError' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Davidh-claranet avatar Jul 13 '22 11:07 Davidh-claranet

Thanks for reporting. @Davidh-claranet , Could you check the output of $Error[0].Exception | fl -f * after you tried to import module Import-Module Az.Accounts? It will share the detailed error message. Resolve-AzError cannot work because module is not imported.

dingmeng-xue avatar Jul 14 '22 02:07 dingmeng-xue

PS /> Import-Module Az.Accounts                         
Import-Module: An item with the same key has already been added. Key: HTTP_PROXY

PS /> $Error[0].Exception | fl -f *

Message        : An item with the same key has already been added. Key: HTTP_PROXY
ParamName      : 
TargetSite     : Void ThrowAddingDuplicateWithKeyArgumentException[T](T)
Data           : {}
InnerException : 
HelpLink       : 
Source         : System.Private.CoreLib
HResult        : -2147024809
StackTrace     :    at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
                    at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
                    at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
                    at Microsoft.Azure.Commands.Common.Authentication.Config.DefaultEnvironmentVariableProvider.List(EnvironmentVariableTarget target)
                    at Microsoft.Azure.Commands.Common.Authentication.Config.Internal.Providers.EnvironmentVariablesConfigurationProvider.Load()
                    at Microsoft.Azure.Commands.Common.Authentication.Config.Internal.ConfigurationRoot..ctor(IList`1 providers)
                    at Microsoft.Azure.Commands.Common.Authentication.Config.Internal.ConfigurationBuilder.Build()
                    at Microsoft.Azure.Commands.Common.Authentication.Config.ConfigManager.BuildConfig()
                    at Microsoft.Azure.Commands.Common.Authentication.Config.ConfigInitializer.InitializeForAzureSession(AzureSession session)
                    at Microsoft.Azure.Commands.Common.Authentication.AzureSessionInitializer.InitializeConfigs(AzureSession session, String profilePath)
                    at Microsoft.Azure.Commands.Common.Authentication.AzureSessionInitializer.CreateInstance(IDataStore dataStore)
                    at Microsoft.Azure.Commands.Common.Authentication.AzureSessionInitializer.<>c.<InitializeAzureSession>b__2_0()
                    at Microsoft.Azure.Commands.Common.Authentication.AzureSession.Initialize(Func`1 instanceCreator, Boolean overwrite)
                    at Microsoft.Azure.Commands.Common.Authentication.AzureSession.Initialize(Func`1 instanceCreator)
                    at Microsoft.Azure.Commands.Common.Authentication.AzureSessionInitializer.InitializeAzureSession()
                    at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.OnImport()
                    at System.Management.Automation.Runspaces.PSSnapInHelpers.ExecuteModuleInitializer(Assembly assembly, IEnumerable`1 assemblyTypes)
                    at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzeModuleAssemblyWithReflection(Assembly assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, String helpFile, 
                 Dictionary`2& cmdlets, Dictionary`2& aliases, Dictionary`2& providers)
                    at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzePSSnapInAssembly(Assembly assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, Dictionary`2& cmdlets, Dictionary`2&       
                 aliases, Dictionary`2& providers, String& helpFile)
                    at System.Management.Automation.Runspaces.InitialSessionState.ImportCmdletsFromAssembly(Assembly assembly, PSModuleInfo module)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadBinaryModule(PSModuleInfo parentModule, String moduleName, String fileName, Assembly assemblyToLoad, String moduleBase, SessionState ss,
                 ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, String prefix, Boolean loadTypes, Boolean loadFormats, Boolean& found, String shortModuleName, Boolean disableFormatUpdates)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadBinaryModule(String moduleName, String fileName, Assembly assemblyToLoad, String moduleBase, SessionState ss, ImportModuleOptions options,
                 ManifestProcessingFlags manifestProcessingFlags, String prefix, Boolean loadTypes, Boolean loadFormats, Boolean& found)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String fileName, String moduleBase, String prefix, SessionState ss, Object privateData, ImportModuleOptions& options,    
                 ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(String fileName, String moduleBase, String prefix, SessionState ss, ImportModuleOptions& options, ManifestProcessingFlags manifestProcessingFlags,  
                 Boolean& found)
                    at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName(ImportModuleOptions importModuleOptions, String name)
                    at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName_WithTelemetry(ImportModuleOptions importModuleOptions, String name)
                    at Microsoft.PowerShell.Commands.ImportModuleCommand.ProcessRecord()
                    at System.Management.Automation.Cmdlet.DoProcessRecord()
                    at System.Management.Automation.CommandProcessor.ProcessRecord()

Davidh-claranet avatar Jul 15 '22 06:07 Davidh-claranet

This may be related to #18424.

We set proxy environment variables as well however if we just pull the image from mcr without setting proxy vars it fails outright. Everything worked properly in 2.7.6.

RickBankers avatar Jul 19 '22 16:07 RickBankers

@Davidh-claranet , @RickBankers , it seems relate to issue https://github.com/Azure/azure-powershell/pull/18312. This issue has been fixed in the latest version of Az.Accounts 2.9.0. Could you update the version and try again?

dingmeng-xue avatar Jul 21 '22 08:07 dingmeng-xue

Still doesn't seem to be fixed. The alpine-3.14 image seems to work fine.

Ubuntu Image

`docker pull mcr.microsoft.com/azure-powershell Using default tag: latest Trying to pull repository mcr.microsoft.com/azure-powershell ... latest: Pulling from mcr.microsoft.com/azure-powershell d5fd17ec1767: Pull complete acf5110a340e: Pull complete de27e63c182a: Pull complete fa3568af4d57: Pull complete f5fb4bd701e8: Pull complete 9776292961b8: Pull complete Digest: sha256:163586739f74a02282a4c2b7f12805b596d6ada983a0ff729196af18ec8c823a Status: Downloaded newer image for mcr.microsoft.com/azure-powershell:latest mcr.microsoft.com/azure-powershell:latest

docker run -it mcr.microsoft.com/azure-powershell pwsh PowerShell 7.2.4 Copyright (c) Microsoft Corporation.

https://aka.ms/powershell Type 'help' to get help.

PS /> connect-azaccount connect-azaccount: The term 'connect-azaccount' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. exit`

Alpine Image

`docker pull mcr.microsoft.com/azure-powershell:alpine-3.14 docker run -it mcr.microsoft.com/azure-powershell:alpine-3.14 pwsh PowerShell 7.2.5 Copyright (c) Microsoft Corporation.

https://aka.ms/powershell Type 'help' to get help.

PS /> connect-azaccount WARNING: Interactive authentication is not supported in this session, please run cmdlet 'Connect-AzAccount -UseDeviceAuthentication'. PS /> exit `

RickBankers avatar Jul 21 '22 14:07 RickBankers

Hello I use the lastest version of the mcr.microsoft.com/azure-powershell image

It still provides Az.Accounts 2.8.0, and not 2.9.0.

PS /> get-module         
ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.8.0                 Az.Accounts
[...]

I tried to force the version :

PS /> Import-Module -Name Az.Accounts -MinimumVersion 2.9.0           
Import-Module: The specified module 'Az.Accounts' with version '2.9.0' was not loaded because no valid module file was found in any module directory.

I don't know how import Az.Accounts 2.9.0

Davidh-claranet avatar Jul 21 '22 16:07 Davidh-claranet

I've got a very similar issue currently regarding Azure DevOps builds which don't run as a root user.

The module location has moved from /usr/local/share/powershell/Modules to /root/.local/share/powershell/Modules in a recent build of the image.

This means any user running as non-root no longer has access to this module as they can't read /root/...

SHAs of a build that works and doesn't work: ✔️ : sha256:163586739f74a02282a4c2b7f12805b596d6ada983a0ff729196af18ec8c823a ❌ : sha256:d7da797d627a135b31acb15329c8a949f06caa963e7c99fc04e63b70d839df75

ElvenSpellmaker avatar Aug 05 '22 10:08 ElvenSpellmaker

Hi, Sorry for your inconvenience. We have made a mistake when last release, and now we’ve repaired it. Please remove the former image and re-pull the latest image of azure powershell and retry. Thanks for your report and if you have any other questions, please feel free to contact us.

Best Regards, Nanxiang From: Davidh-claranet @.> Sent: Friday, July 22, 2022 12:01 AM To: Azure/azure-powershell @.> Cc: Nanxiang Liu @.>; Assign @.> Subject: Re: [Azure/azure-powershell] Connect-AzAccount: The term 'Connect-AzAccount' is not recognized as a name of a cmdlet (Issue #18928)

Hello I use the lastest version of the mcr.microsoft.com/azure-powershell image

It still provides Az.Accounts 2.8.0, and not 2.9.0.

PS /> get-module

ModuleType Version PreRelease Name ExportedCommands


Script 2.8.0 Az.Accounts

[...]

I tried to force the version :

PS /> Import-Module -Name Az.Accounts -MinimumVersion 2.9.0

Import-Module: The specified module 'Az.Accounts' with version '2.9.0' was not loaded because no valid module file was found in any module directory.

I don't know how import Az.Accounts 2.9.0

— Reply to this email directly, view it on GitHubhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FAzure%2Fazure-powershell%2Fissues%2F18928%23issuecomment-1191666043&data=05%7C01%7Cnanxiangliu%40microsoft.com%7Ca8bcf5439ad241a03efb08da6b322744%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637940160427316683%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Fpg4ZIREWyShllspADNsg9AvWzv0hZeLTNneCN1HzwI%3D&reserved=0, or unsubscribehttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAH56LSRFJ5BFE3G53MFFTZTVVFX2LANCNFSM53OMSDOQ&data=05%7C01%7Cnanxiangliu%40microsoft.com%7Ca8bcf5439ad241a03efb08da6b322744%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637940160427316683%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=hxf3hZfl7yBNyVLbUIQoNECQx2DLzkK34Fc0mD99drk%3D&reserved=0. You are receiving this because you were assigned.Message ID: @.***>

Nickcandy avatar Oct 11 '22 09:10 Nickcandy

Hello I confirm the fix. Thank you !

Davidh-claranet avatar Oct 18 '22 09:10 Davidh-claranet