Я пытаюсь собрать все мобильные приложения с их правилами обнаружения всего за один вызов бета-версии GraphAPI. При использовании PostMan отправка 1 запроса GET https://graph.microsoft.com/beta/deviceAppManagement/mobileApps?$filter=isof('microsoft.graph.win32LobApp')&$top=1000 вернет вам список 100 лучших мобильных приложений в формате JSON. Каждый объект будет иметь правила обнаружения, содержащие различные данные, что на самом деле не так при выполнении того же на C# с использованием библиотеки Graph Beta (по крайней мере, насколько мне известно).
Вот метод, который я написал, чтобы попытаться получить идентификаторы назначений, правила обнаружения и CreateOn:
public async Task<List<GraphResponseModel>> GetAllWin32LobAppWithDetectionRules()
{
try
{
Win32LobAppRegistryDetection detectionRule = null;
List<GraphResponseModel> graphResponseModelList = new();
List<string?> idsFromAssignment = [];
// Get all Win32LobApps
var mobileApps = await _graphClient.DeviceAppManagement.MobileApps.GetAsync(context =>
{
context.QueryParameters.Filter = "isof('microsoft.graph.win32LobApp')";
context.QueryParameters.Expand = new string[] {"assignments"};
});
foreach (var mobileApp in mobileApps.Value)
{
mobileApp.Assignments.ForEach(assignment =>
{
idsFromAssignment.Add(assignment.Id);
});
// Cast the mobileApp to a Win32LobApp
var win32LobApp = (Win32LobApp)mobileApp;
_detectionRulesModel = null;
foreach (var detection in win32LobApp.DetectionRules)
{
if (detection.OdataType == "#microsoft.graph.win32LobAppRegistryDetection")
{
detectionRule = (Win32LobAppRegistryDetection)detection;
_detectionRulesModel = new DetectionRulesModel(detectionRule.OdataType, (bool)detectionRule.Check32BitOn64System, detectionRule.KeyPath, detectionRule.ValueName,detectionRule.DetectionType.Value.ToString(), detectionRule.Operator.ToString(), detectionRule.DetectionValue);
}
else
{
continue;
}
_createdOn = mobileApp.CreatedDateTime.Value.DateTime;
graphResponseModelList.Add(new GraphResponseModel(idsFromAssignment, _detectionRulesModel, _createdOn));
}
}
return graphResponseModelList;
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
К сожалению, я получаю ответ со списком, содержащим фактическое количество программного обеспечения, которым я владею, но заполнено только поле _createdOn, остальные поля пусты.





Я получаю ответ со списком, содержащим фактическое количество программного обеспечения, которым я владею, но заполнено только поле
_createdOn, остальные поля пусты.
Сначала убедитесь, что они правильно получают доступ к правилам обнаружения и назначениям. Затем правильно добавьте значения в модель внутри цикла.
Код:
public async Task<List<GraphResponseModel>> GetAllWin32LobAppWithDetectionRules()
{
try
{
List<GraphResponseModel> graphResponseModelList = new List<GraphResponseModel>();
// Get all Win32LobApps
var mobileApps = await _graphClient.DeviceAppManagement.MobileApps.GetAsync(context =>
{
context.QueryParameters.Filter = "isof('microsoft.graph.win32LobApp')";
context.QueryParameters.Expand = new string[] { "assignments", "detectionRules" };
});
foreach (var mobileApp in mobileApps.Value)
{
List<string> assignmentIds = mobileApp.Assignments.Select(assignment => assignment.Id).ToList();
DateTime createdOn = mobileApp.CreatedDateTime.Value.DateTime;
List<DetectionRulesModel> detectionRulesModels = new List<DetectionRulesModel>();
// Check if the mobileApp has detection rules
if (mobileApp.DetectionRules != null)
{
foreach (var detectionRule in mobileApp.DetectionRules)
{
if (detectionRule.ODataType == "#microsoft.graph.win32LobAppRegistryDetection")
{
var win32LobAppRegistryDetection = (Win32LobAppRegistryDetection)detectionRule;
DetectionRulesModel detectionRulesModel = new DetectionRulesModel(
detectionRule.ODataType,
win32LobAppRegistryDetection.Check32BitOn64System,
win32LobAppRegistryDetection.KeyPath,
win32LobAppRegistryDetection.ValueName,
win32LobAppRegistryDetection.DetectionType?.ToString(),
win32LobAppRegistryDetection.Operator?.ToString(),
win32LobAppRegistryDetection.DetectionValue
);
detectionRulesModels.Add(detectionRulesModel);
}
}
}
graphResponseModelList.Add(new GraphResponseModel(assignmentIds, detectionRulesModels, createdOn));
}
return graphResponseModelList;
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
Выше мы напрямую обращаемся к mobileApp.Assignments и mobileApp.DetectionRules и правильно заполняем списки DetectionRulesModel и assignmentIds внутри цикла.
Затем, добавив заполненную модель в список graphResponseModelList вне цикла.
Ниже показано, когда было создано мобильное приложение.
{
"assignmentIds": ["assignment1", "assignment2"],
"detectionRules": {
"OdataType": "#microsoft.graph.win32LobAppRegistryDetection",
"Check32BitOn64System": true,
"KeyPath": "HKEY_LOCAL_MACHINE\\Software\\MyApp",
"ValueName": "Version",
"DetectionType": "RegistryValueExists",
"Operator": "Equals",
"DetectionValue": "1.0"
},
"createdOn": "2024-05-10T15:30:00Z"
}
Ссылка:
Ваша проблема решена? Если нет, проверьте, помогает ли приведенное ниже решение.