azure - 无法注销并使用 Azure power shell 进行非交互式登录
问题描述
我已经打开powershell并通过交互式登录登录到azure帐户。然后我想做一个非交互式登录,我有代码。PFB 是我的代码。
但是当我使用下面的代码时,它仍然从缓存中获取用户,即使我也输入了错误的密码,它也不会抛出任何错误。
$subscriptionId="Subscription id here"
$tenantid="tenant id here"
$clientid="clinent id here" #appid
$password="password" #i have given the wrong password here
$securePassword = $password | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $clientid, $securePassword
#Connect-AzureRmAccount -ServicePrincipal -Credential $credential -TenantId $tenantid -Subscription $subscriptionId
Add-AzureRmAccount -Credential $credential -TenantId $tenantID -ServicePrincipal -Subscription $subscriptionId
在这里,我想从 Azure 电源外壳注销并使用服务主体(Azure 应用程序)的非交互式登录。有人可以帮帮我吗。
解决方案
要注销帐户,您可以使用此命令Remove-AzureRmAccount
,或关闭 powershell 并打开一个新的。
要使用服务主体使用非交互式登录,您可以使用以下命令,密码是您的 AD 应用程序的密码。
$azureAplicationId ="Azure AD Application Id"
$azureTenantId= "Your Tenant Id"
$azurePassword = ConvertTo-SecureString "password" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Add-AzureRmAccount -Credential $psCred -TenantId $azureTenantId -ServicePrincipal
推荐阅读
- python - ADF 使用 python 删除活动 - 无法创建日志记录
- postgresql - 如何连接到在 docker 中运行的 postgres 实例?
- vuejs2 - 如何在 Vuejs 中有条件地显示数据
- vb.net - 创建一个等待延迟替代 Application.DoEvents
- .htaccess - 将旧网址重定向到 htaccess 中的新网址?
- python - 可通过密码访问的 Django 页面
- android - 是否可以要求 Android Keystore 的应用特定 PIN 身份验证
- average - 将行添加到列
- javascript - 正确格式化文档标题的时间
- vue.js - 在 vue.js 浏览器错误中编译失败