I’m try to get all MobileApps together with their Detection Rules in just 1 call to GraphAPI Beta. Using PostMan, sending 1 GET request https://graph.microsoft.com/beta/deviceAppManagement/mobileApps?$filter=isof('microsoft.graph.win32LobApp')&$top=1000
would return you a list of Top 100 MobileApps in JSON format. Each object would have a Detection Rules, containing various data which is not really the case when doing the same in C# using the Graph Beta library(at least to my knowledge).
Here’s a method I wrote to try and get the assignment ids, detection rules and createdOn:
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;
}
}
Unfortunately, I get a response back with the list containing the actual amount of software I own, but only the _createdOn
field is populated, other fields are empty.
Gluhaia_Muha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.