使用Windows Powershell自动身份验证为Azure作为服务主体 [英] Automate Authentication to Azure as Service Principal using Windows Powershell

查看:81
本文介绍了使用Windows Powershell自动身份验证为Azure作为服务主体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Powershell来执行一些自动化的Jenkins作业.为了完成这项工作,我需要以非交互方式认证为服务主体.

I need to use Powershell for some automated Jenkins jobs. To do the work, I need to authenticate as a Service Principal in a non-interactive fashion.

使用Azure CLI,可以使用以下命令以非交互方式完成此操作:

With the Azure CLI, this can be accomplished non-interactively using the following command:

az login --service-principal -u "$client_id" -p "$client_secret" -t "$tenant_id"

但是,事实证明,使用Connect-AzAccount cmdlet for Powershell来完成此任务非常困难.无论如何,使用Powershell cmdlet可以达到与上述相同的结果吗?所有选项

However, accomplishing this using the Connect-AzAccount cmdlet for Powershell is proving to be tough. Is there anyway to achieve the same result as above using a Powershell cmdlet? All of the options described here seem to be interactive only.

任何帮助将不胜感激.

推荐答案

要使用Connect-AzAccount非交互式登录,请尝试以下命令,strong password是您的客户端密码,它对我而言很好用.

To use Connect-AzAccount to login non-interactively, try the command as below, the strong password is your client secret, it works fine on my side.

$azureAplicationId ="Azure AD Application Id"
$azureTenantId= "Your Tenant Id"
$azurePassword = ConvertTo-SecureString "strong password" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Connect-AzAccount -Credential $psCred -TenantId $azureTenantId  -ServicePrincipal 

这篇关于使用Windows Powershell自动身份验证为Azure作为服务主体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆