2017-06-29 92 views
0

我有一個電子郵件帳戶,它是一個安全組,其中很少有成員。我試圖找出該組的店主的電子郵件地址,但我一直無法弄清楚。獲取.NET Azure Active Directory組中的所有者

下面是源代碼

ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(serviceRoot, async() => await Task.FromResult(accessToken)); 
    var group = (Group)await activeDirectoryClient.Groups.Where(u => u.Mail == "[email protected]").ExecuteSingleAsync();. 
    var groupFetcher = activeDirectoryClient.Groups.GetByObjectId(group.ObjectId); 
    var membersResult = groupFetcher.Members.ExecuteAsync().Result; 
    var ownerResult = groupFetcher.Owners.ExecuteAsync().Result; 

後,我執行此代碼,可以看我的小​​組成員但瓦特HY ownerResult變量始終是空如何檢索組的所有者?

回答

2

我正在測試使用下面的代碼(Microsoft.Azure.ActiveDirectory.GraphClient與版本2.1.1),它適用於我。請確保該組已經分配了所有者。

var group = (Group) client.Groups.Where(u => u.Mail == "[email protected]").ExecuteSingleAsync().Result; 
var groupFetcher = client.Groups.GetByObjectId(group.ObjectId); 
//var membersResult = groupFetcher.Members.ExecuteAsync().Result; 
var ownerResult = groupFetcher.Owners.ExecuteAsync().Result; 
foreach (var owner in ownerResult.CurrentPage) 
    Console.WriteLine(((Microsoft.Azure.ActiveDirectory.GraphClient.User)owner).DisplayName); 

您可以從Azure的門戶檢查它像下圖: enter image description here

如果車主存在,我也建議你使用招來檢查響應是否有望捕獲請求。

+0

謝謝你的工作! – user3587624