[英]How to connect-azaccount in Azure DevOps release pipeline
In the release pipeline, I am trying to connect to Azure AD by using Connect-Azaccount so I can run Get-AzADgroup to retrieve some Az AD group names and their guid and output to variables. 在发布管道中,我尝试使用Connect-Azaccount连接到Azure AD,以便我可以运行Get-AzADgroup来检索某些Az AD组名称及其guid并将其输出到变量。
I created Azure Powershell task with the following inline script. 我使用以下嵌入式脚本创建了Azure Powershell任务。
(Get-AzADGroup -DisplayName "group-name").origin (Get-AzADGroup -DisplayName“ group-name”)。起源
It seems you need to use a non-interactive login, follow the steps as below. 似乎您需要使用非交互式登录,请按照以下步骤操作。
1. Create an Azure Active Directory application and create a secret for the app, save the secret and get values for signing in . 1. 创建一个Azure Active Directory应用程序,并为该应用程序 创建一个秘密 ,保存该秘密并获取用于登录的值 。
2.In your AD App -> API permissions
-> Add a permission
-> select Azure Active Directory Graph
-> Application permissions
-> Directory.Read.All
-> click Add permissions
-> click Grant admin consent for xxx
, refer to the screenshot. 2.在您的AD App中->
API permissions
-> Add a permission
->选择Azure Active Directory Graph
-> Application permissions
-> Directory.Read.All
>单击Add permissions
->单击Grant admin consent for xxx
,请参阅屏幕截图。
3.Try the script as below, use the values which you get in step 1, it works fine on my side. 3.尝试如下所示的脚本,使用在步骤1中获得的值,它对我而言效果很好。
Note : You need to use the Task version
with 4.*(preview)
when you use Az
powershell module. 注意 :使用
Az
powershell模块时,需要使用带有4.*(preview)
的Task version
。
$azureAplicationId ="<your ad app application id>"
$azureTenantId= "<your tenant id>"
$azurePassword = ConvertTo-SecureString "<the secret of your ad app>" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Connect-AzAccount -Credential $psCred -TenantId $azureTenantId -ServicePrincipal
#I just test to get all groups, you could do other operations
Get-AzADGroup
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.