Automate Authentication to Azure as Service Principal using Windows Powershell

纵饮孤独 提交于 2020-01-06 08:12:59

问题


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.

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"

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.

Any help would be greatly appreciated.


回答1:


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 



来源:https://stackoverflow.com/questions/55582300/automate-authentication-to-azure-as-service-principal-using-windows-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!