azure - 如何在 Powershell Core 中连接-AzAccount(无提示)?
问题描述
我确实看到了这个问题:Connect-AzAccount without prompt
但是当我尝试接受的答案时,我收到以下错误:
[6/12/2020 12:36:20 AM] ERROR: Connect-AzAccount : Username + Password authentication is not supported in PowerShell Core. Please use device code authentication for interactive log in, or Service Principal authentication for script log in.
所以我转到了 Connect-AzAccount 文档的示例 3,它指定了“服务主体”身份验证方法,因此我将两者混合,因为建议的 vanillaGet-Credential
会触发另一个交互式会话。所以现在是脚本:
$User = "myemail@gmail.com"
$PWord = ConvertTo-SecureString -String "**********" -AsPlainText -Force
$tenant = "f*********************************"
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User,$PWord
# $Credential = Get-Credential
Connect-AzAccount -Credential $Credential -Tenant $tenant -ServicePrincipal
这带来了我的下一个错误:[6/12/2020 12:45:45 AM] ERROR: Connect-AzAccount : AADSTS700016: Application with identifier 'myemail' was not found in the directory 'f*********************************'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.
在这一点上我真的很困惑,因为我在 Azure 中所做的只是:
- 创建新的 Azure 帐户
- 通过 UI 预配 Azure API 管理实例(顺便说一句,大约需要 20 分钟)
- 尝试使用上面的代码在本地连接到 Powershell Azure 函数内的 Azure。
我认为我提供的信息或我的配置方式有问题。
$User
是我注册 Azure 时使用的电子邮件。
$PWord
是我的 Azure 密码
$tenant
是我打开 Azure AD 时看到的第一件事:
我尝试通过 Powershell Core 连接到 Azure 的方式有什么问题?
解决方案
基于示例 3,它要求输入您的应用程序 ID 作为用户名和服务主体机密作为密码。
因此,您首先需要创建一个服务主体。然后使用其应用程序 ID 和客户端密码作为凭证。
$User = "{application id}"
$PWord = ConvertTo-SecureString -String "{client secret}" -AsPlainText -Force
推荐阅读
- excel - 如何在保留文件缩进的同时将excel文件保存为csv文件?
- node.js -
- ruby-on-rails - 如何修复 WSL2 中的“Selenium::WebDriver::Error::WebDriverError: chrome not reachable”
- python - 如何使用 pandas 将 8760x2 DataFrame 转换为 365x25 DataFrame?
- flutter - Flutter 中的设备国家
- kubernetes - 是否有可能在 kubernetes 部署期间从不重新启动策略,而仅在部署期间?
- javascript - 使用 Typescript 从 Mongoose 模型访问文档属性
- java - 从 H2 迁移到 Ehcache
- mysql - 如何使用 SQL 中的中间表从外部表中选择每个字段?
- android - 在 Glide 中使用 @GET 请求从 API 加载图像