简体   繁体   English

Get-AzADUser 在 Azure Devops MS 托管代理上返回空

[英]Get-AzADUser returns empty on Azure Devops MS hosted agent

I am using Az Powershell Module on Azure Devops Pipeline Task.我在 Azure Devops 管道任务上使用 Az Powershell 模块。 My problem is that Get-AzADUser command returns empty on Azure Devops MS hosted agent although it functions well on Azure Cloud Shell and returns the AzAD Users .我的问题是Get-AzADUser命令在Azure Devops MS hosted agent返回空,尽管它在Azure Cloud Shell上运行良好并返回 AzAD Users 。 I am using the same account for both (Cloud Shell and Azure Devops).我对两者(Cloud Shell 和 Azure Devops)使用相同的帐户。

Here below are the logs of the Azure Devops Task:以下是 Azure Devops 任务的日志:

2020-10-23T09:04:34.5200816Z ##[section]Starting: Azure PowerShell script: FilePath
2020-10-23T09:04:34.5561322Z ==============================================================================
2020-10-23T09:04:34.5562144Z Task         : Azure PowerShell
2020-10-23T09:04:34.5563006Z Description  : Run a PowerShell script within an Azure environment
2020-10-23T09:04:34.5563312Z Version      : 5.176.2
2020-10-23T09:04:34.5564072Z Author       : Microsoft Corporation
2020-10-23T09:04:34.5565422Z Help         : https://aka.ms/azurepowershelltroubleshooting
2020-10-23T09:04:34.5566084Z ==============================================================================
2020-10-23T09:04:36.0669385Z Generating script.
2020-10-23T09:04:36.1560120Z ========================== Starting Command Output ===========================
2020-10-23T09:04:36.1824475Z ##[command]"C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\11730398-1e70-4056-a1ec-5d9694307da4.ps1'"
2020-10-23T09:04:39.1363993Z ##[command]Import-Module -Name C:\Modules\az_4.7.0\Az.Accounts\1.9.4\Az.Accounts.psd1 -Global
2020-10-23T09:04:48.4455502Z ##[command]Clear-AzContext -Scope Process
2020-10-23T09:04:49.5325261Z ##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
2020-10-23T09:04:49.8445719Z ##[command]Connect-AzAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
2020-10-23T09:04:52.0059255Z ##[command] Set-AzContext -SubscriptionId *** -TenantId ***
2020-10-23T09:04:52.9718588Z Get-AzADUser

What should i do so that it returns the ADUser objects?我应该怎么做才能返回 ADUser 对象?

In Azure Cloud Shell, it uses the credential of the user logged in the azure portal, if it works, it just means your user account has the permission to list the users.在 Azure Cloud Shell 中,它使用登录到 azure 门户的用户的凭据,如果它有效,则仅表示您的用户帐户具有列出用户的权限。

In the devops pipeline, it uses the credential of the service principal which is configured in the Project Settings -> Service connections , not the user account logged in the devops.在 devops 管道中,它使用在Project Settings -> Service connections配置的服务主体的凭据,而不是在 devops 中登录的用户帐户。

To solve the issue, navigate to the Project Settings in devops -> Service connections -> find the service connection you used -> click Manage Service Principal .要解决此问题,请导航到 devops 中的Project Settings -> Service connections -> 找到您使用的服务连接 -> 单击Manage Service Principal

在此处输入图片说明

Then it will open the Azure AD App page of the service principal, navigate to the API permissions -> add the Application permission Directory.Read.All of Azure Active Directory Graph like below( Note : It should be Azure Active Directory Graph , not Microsoft Graph ).然后它会打开服务主体的 Azure AD App 页面,导航到API permissions -> 添加应用权限Directory.Read.All Azure Active Directory Graph如下(注意:它应该是Azure Active Directory Graph ,而不是Microsoft Graph )。

在此处输入图片说明

在此处输入图片说明

Note: Don' forget to click the Grant admin consent for xxx button at last.注意:最后不要忘记单击Grant admin consent for xxx按钮。

在此处输入图片说明

Then go to your devops to have a try, it should work.然后去你的 devops 试一试,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure 自动化:Runbook、RunAs 帐户:如何允许访问 AAD(例如 Get-AzADUser)? - Azure Automation: Runbook, RunAs Account: How to allow access to AAD (e.g. for Get-AzADUser)? Azure Devops MS Hosted Agent Pool 代理机 - Azure Devops MS Hosted Agent Pool Agent machine Azure DevOps 托管代理上的 Azure 功能包? - Azure Feature Pack on Azure DevOps Hosted Agent? 托管代理失败的 Azure DevOps 构建管道 - Azure DevOps build pipeline with hosted agent failing Azure DevOps MS 托管代理查询仅锁定到内部 IP 的网站? - Azure DevOps MS-Hosted agent querying a website that is locked down to an internal IP only? 我无法从 Get-AzADUser 中找到足够的属性,是否有任何替代方法可以使用完整的属性? - I am not able to find enough properties from Get-AzADUser, is there any alternative to use complete properties? Azure DevOps 托管生成代理 MSI - Azure DevOps Hosted Build Agent MSI Azure DevOps(VSTS)-在托管代理上使用Azure Az PowerShell - Azure DevOps (VSTS) - using Azure Az PowerShell on a Hosted Agent Azure Devops 托管代理的 ARM64 标签 - ARM64 label of Azure Devops hosted agent Azure DevOps托管的ubuntu代理更新应用程序网关的问题 - Azure DevOps hosted ubuntu agent issue updating Application Gateway
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM