[英]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.