Close Menu
    Facebook X (Twitter) Instagram
    Sunday, May 11
    X (Twitter) LinkedIn
    All about Endpoint Management
    • Home
    All about Endpoint Management
    Home»Office 365»EMS»Identify Users’ Enrolled Mobile Devices (iOS and Android) with KQL

    Identify Users’ Enrolled Mobile Devices (iOS and Android) with KQL

    Eswar KonetiBy Eswar KonetiOctober 30, 11:22 pm4 Mins Read EMS 1,580 Views
    Share
    Facebook Twitter LinkedIn Reddit

    Recently, I received a request from a customer to identify users who have enrolled their mobile devices, specifically iOS and Android, managed by Intune.

    Initially, I explored the Intune console, applying filters based on the operating system to generate a list of mobile devices and their associated users. However, this approach only provided a basic view, requiring me to export the data to a CSV file and use Excel formulas to identify users with both iOS and Android devices—an arduous and time-consuming process.

    image

    Streamlining the Process with KQL and Power BI

    To simplify this use case, I turned to KQL (Kusto Query Language) within Azure Log Analytics. By integrating this with Power BI or Azure workbooks, I was able to create a more efficient and visually engaging solution.

    Prerequisites: Ensure that your Diagnostic Settings for device logs are enabled in your Log Analytics workspace. If you’ve already configured this, you’re ready to start using KQL and Power BI.

    image

    The KQL query analyzes device data from the Intune Log Analytics workspace, identifying users who have both iOS and Android devices. It includes a subquery that summarizes the count of iOS and Android devices for each user and creates a flag to indicate whether a user has both types of devices.

    I have added new column for devices that have not contacted Intune within the last 30 days are marked as "Inactive," but you can adjust this timeframe to suit your needs.

    KQL Queries for Device Enrollment

    Here’s a KQL query to find users who have enrolled both iOS and Android devices (regardless of the enrollment method):

    //Define Variables
    let startDate = ago(30d);
    let endDate = now();
    let iOS_check = dynamic(["iOS/iPadOS"]);
    // Subquery to calculate iOS and android devices (Both)
    let UserDeviceSummary = IntuneDevices
         | where ManagedBy != "MDE"
         | summarize
             has_ios = countif(OS == "iOS/iPadOS"),
             has_android = countif(OS contains "Android")
           by UPN
         | extend iOSAndAndroid = iff(has_ios > 0 and has_android > 0, "Yes", "No");
    // Main query to get device details and join with BothDevices column
    IntuneDevices
    | summarize arg_max(TimeGenerated, *) by SerialNumber, DeviceId
    | where (OS in (iOS_check) or OS contains "Android")
           and ManagedBy != "MDE"
    | extend DeviceUrl = strcat('
    https://endpoint.microsoft.com/#blade/Microsoft_Intune_Devices/DeviceSettingsBlade/overview/mdmDeviceId/', DeviceId)
    | extend Active = iff((todatetime(LastContact) between (startDate .. endDate)), "Active", "Inactive")
    | join kind=inner UserDeviceSummary on UPN
    | where iOSAndAndroid == "Yes"
    | project UPN, UserEmail, DeviceName, OS, OSVersion, Manufacturer, Model, CreatedDate,LastContact,Active,DeviceUrl, iOSAndAndroid

    For users who have enrolled both iOS and Android devices specifically with a Personally-Owned Work Profile, you can use the following KQL query:

    //Define Variables
    let startDate = ago(30d);
    let endDate = now();
    let ios_android_check = dynamic(["iOS/iPadOS", "Android (Personally-Owned Work Profile)"]);
    // Subquery to calculate BothDevices column
    let UserDeviceSummary = IntuneDevices
         | where OS in (ios_android_check) and ManagedBy != "MDE" and CompliantState != "ConfigManager"
         | summarize has_ios = countif(OS == "iOS/iPadOS"), has_android = countif(OS == "Android (Personally-Owned Work Profile)") by UPN
         | extend iOSAndAndroid = iff(has_ios > 0 and has_android > 0, "Yes", "No");
    // Main query to get device details and join with BothDevices column
    IntuneDevices
    | summarize arg_max(TimeGenerated, *) by SerialNumber, DeviceId
    | where OS in (ios_android_check) and ManagedBy != "MDE" and CompliantState != "ConfigManager"
    | extend DeviceUrl = strcat('
    https://endpoint.microsoft.com/#blade/Microsoft_Intune_Devices/DeviceSettingsBlade/overview/mdmDeviceId/', DeviceId)
    | extend Active = iff((todatetime(LastContact) between (startDate .. endDate)), "Active", "Inactive")
    | join kind=inner UserDeviceSummary on UPN
    | where iOSAndAndroid == "Yes"
    | project UPN, UserEmail, DeviceName, OS, OSVersion, Manufacturer, Model, CreatedDate,LastContact,Active,DeviceUrl, iOSAndAndroid

    Output Visualization:

    image

    You can use these KQL queries in Power BI for enhanced data visualization, making it easier to present and analyze the enrolled devices.

    I hope this guide helps you streamline your device management process!

    For more information on KQL functions, refer to the official documentation: KQL Aggregation Functions

    Dynamic query EMS intune iOS and android KQL Kusto powerBI
    Share. Twitter LinkedIn Email Facebook Reddit

    Related Posts

    Optimize Your Intune Workflow with a Powerful Browser Extension

    March 22, 10:39 am

    Troubleshooting Windows Hello for Business PIN Reset Issues – Something went wrong

    March 06, 9:48 pm

    Migrate Microsoft 365 Updates from SCCM/MECM to Intune for Co-Managed Devices

    February 11, 9:50 pm

    1 Comment

    1. Brett Abbott on November 1, 2024 9:24 PM

      Thanks for this Eswar, this is really useful.

      Reply

    Leave a ReplyCancel reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Sign Up

    Get email notifications for new posts.

    Author

    I’m Eswar Koneti ,a tech enthusiast, security advocate, and your guide to Microsoft Intune and Modern Device Management. My goal? To turn complex tech into actionable insights for a streamlined management experience. Let’s navigate this journey together!

    Support

    Awards

    Archives

    © Copyright 2009-2024 Eswar Koneti, All rights reserved.

    Type above and press Enter to search. Press Esc to cancel.