首页 > 解决方案 > 在 azure 中运行 powershell 脚本时无法获取租户组织的令牌

问题描述

我正在尝试从 powershell 连接到 azure 门户。我无法连接。以下是错误信息。Connect-AzAccount :无法再找到默认上下文;请运行“Get-AzContext -ListAvailable”以查看所有可用上下文,“Select-AzContext”选择新的默认上下文,或“Connect-AzAccount”以使用新帐户登录。在行:1 字符:1

调试:AzureQo​​SEvent:CommandName - Connect-AzAccount;IsSuccess - 错误;持续时间 - 00:00:00.0390377;; 异常 - System.Management.Automation.PSInvalidOperationException:无法再找到默认上下文;请运行“Get-AzContext -ListAvailable”以查看所有可用上下文,“Select-AzContext”以选择新的默认上下文,或“Connect-AzAccount”以使用新帐户登录。在 Microsoft.Azure.Commands.Common.Authentication.Models.AzureRmProfile.get_DefaultContext() 在 Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient..ctor(IProfileOperations profile) 在 Microsoft.Azure.Commands.Profile.Common.AzureContextModificationCmdlet。修改上下文(动作2 contextAction) at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.SetContextWithOverwritePrompt(Action3 setContextAction) 在 Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.ExecuteCmdlet() 在 Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord(); 调试:完成发送指标。调试:晚上 8:08:57 - ConnectAzureRmAccountCommand 结束处理。

标签: azurepowershell

解决方案


尝试运行

Clear-AzContext

如果再次遇到问题,请手动删除文件.Azure\AzureRMContext.json.Azure\AzureRmContextSettings.json

如果是 windows ,你会发现上面的文件夹/文件,c:\users\yourname\或者如果它是 Linux /home/yourname/


推荐阅读