public async Task <HashSet <DirectoryObject> > DeviceOwners() { try { var directoryRoles = await GraphServiceHelper.GetDirectoryRolesAsync(_graphClient, _httpContext); var devices = await GraphServiceHelper.GetDevicesAsync(_graphClient, _httpContext); HashSet <DirectoryObject> ownersList = new HashSet <DirectoryObject>(); await devices. Where(_ => _.DisplayName != null). ForEachAsync(async _ => { _deviceObjectIdToDeviceId.Add(_.DeviceId, _.Id); var ownerList = (await GraphServiceHelper.GetDeviceOwners(_graphClient, _httpContext, _.Id)) .Where(__ => __ != null) .ToList(); BloodHoundHelper.DeviceOwners(_, ownerList); if (Startup.IsCosmosDbGraphEnabled) { CosmosDbGraphHelper.DeviceOwners(_, ownerList, directoryRoles); } ownersList.UnionWith(ownerList); }); return(ownersList); } catch (Exception ex) { _logger.Error(ex, $"{nameof(DeviceOwners)} {ex.Message} {ex.InnerException}"); return(null); } }