简体   繁体   English

如何使用 Azure Mgmt SDK fluent 获取 Active Directory 用户总数

[英]How to get total count of Active Directory users by using of Azure Mgmt SDK fluent

I am using https://www.nuget.org/packages/Microsoft.Azure.Management.Fluent for getting resources in Azure with programmatically(C# .NET-Core Web app) and tried to get resources information by providing service principals as below.... I am using https://www.nuget.org/packages/Microsoft.Azure.Management.Fluent for getting resources in Azure with programmatically(C# .NET-Core Web app) and tried to get resources information by providing service principals as below... .

string subscriptionId="XXX"; 
   AzureCredentials cred = new 
             AzureCredentialsFactory().FromServicePrincipal(UIConstants.ClientID, 
             UIConstants.Secret, UIConstants.Tenant,AzureEnvironment.AzureGlobalCloud);                      
            
    var azure = Azure.Configure()
                     .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic) 
                     .Authenticate(cred) 
                     .WithSubscription(subscriptionId);

When I tried to get total numbers of count of Active Directory users like this:当我尝试获取这样的 Active Directory 用户总数时:

int identity = azure.AccessManagement.ActiveDirectoryUsers.List().ToArray().Length;

I got this exception in code:我在代码中遇到了这个异常:

Operation returned an invalid status code 'Forbidden'操作返回无效状态代码“禁止”

Please help me to fix above issue..请帮我解决上述问题..

Thanks, Tutul谢谢, 图图尔

Azure resources like VM, storages are stored under the subscription. Azure VM、存储等资源存储在订阅下。 But AAD users are stored under directory.但 AAD 用户存储在目录下。

You need to assign the service principal a Directory readers role.您需要为服务主体分配Directory readers角色。

Go to Azure Portal -> Azure Active Directory -> Roles and administrators -> Directory readers -> +Add assignments , enter the client id of the service principal. Go to Azure Portal -> Azure Active Directory -> Roles and administrators -> Directory reader of the principal -> +Add assignments ,进入服务客户端。

Now the service principal should have access to the Azure AD users.现在服务主体应该可以访问 Azure AD 用户。

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

相关问题 如何使用 Azure Mgmt SDK fluent 获取所有快照 - How to get all snapshot by using of Azure Mgmt SDK fluent 如何使用 Azure Mgmt SDK fluent 获取端点统计信息和危险端点列表 - How to get list of Endpoint Statistics and Dangerous Endpoints by using of Azure Mgmt SDK fluent 如何使用 Azure Mgmt SDK fluent 获取空资源组列表 - How to get list of Empty Resource Groups by using of Azure Mgmt SDK fluent 使用户进入Azure活动目录 - To get users in azure active directory 如何使用Azure Active Directory图谱API获取属于AppRole的所有用户 - How to get all users that belong in an AppRole using Azure Active Directory Graph API How to get Azure Storage Account Key (connectionString) using azure .net sdk or fluent API? - How to get Azure Storage Account Key (connectionString) using azure .net sdk or fluent API? 如何使用LINQ to LDAP获取活动目录中的用户列表? - how can get List of users in active directory using LINQ to LDAP? 如何获得Active Directory中文件夹的用户? - How I get the users of a folder in Active Directory? 如何从Active Directory中获取用户头像? - How to get users avatar from Active Directory? 从 Azure 云中 Windows Server 上运行的 Active Directory 获取用户 - Get Users from Active Directory running on Windows Server in Azure Cloud
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM