MS Intune Integration using Script - v1

MS Intune Integration using Script - v1

This article guides you through the process of integrating Intune data into SDP using a Python script.

 

Prerequisites:  -

  1. Python 3.6 or above
    Ensure Python is installed and added to your PATH. Use python --version or python3 --version to verify.

  2. Required Python Libraries:

    • msal

    • requests

    • urllib3

  1. Install them using:

 pip install msal requests urllib3 

            If the above command doesn't work, try installing them individually i.e, pip install msal 
  1. Azure and SDP Credentials:

    • Client ID, Client Secret, and Tenant ID from Microsoft Graph API.

    • SDP API Key and SDP URL.

      • To generate an SDP API Key, navigate to:
        ADMIN -> Integration Key -> New


Step 1: Register Application in Intune  

1.1 Create a Client ID and Tenant ID:  

  1. Log in to Azure Portal.

  2. Navigate to Azure Active Directory > App registrations.

  3. Click New registration and:

    • Enter your app’s name.

    • Keep Accounts in this organizational directory only selected.

    • Click Register.

  1. Copy the Application (client) ID and Directory (tenant) ID from the app’s overview.

1.2 Create a Client Secret:  

  1. Go to Certificates & secrets > Client secrets > New client secret.

  2. Provide a description and set Expires to Never.

  3. Click Add and copy the client secret value.

1.3 Add Permissions:  

  1. Navigate to API permissions > Add a permission.

  2. Select Microsoft Graph > Application permissions.

  3. Search and select:

    • DeviceManagementManagedDevices.Read.All.

  1. Click Add permissions and then Grant admin consent for <app name>.

 

 

 

Step 2: Configure the Python Script  

In the provided Python script:

  1. Replace placeholders with your details:

    • "Your_Client_ID" with your Client ID.

    • "Your_Client_Secret" with your Client Secret.

    • "Your_Tenant_ID" with your Tenant ID.

    • "SDP_URL" with your SDP server URL (e.g., https://abc.mdu.zohocorpin.com, without a trailing /).

    • "API_KEY" with the SDP API Key generated in ADMIN -> Integration Key.

  1. Map additional fields in SDP:

    • Create Additional Fields for {last connected time, imei, phone number, operation system, os version, wifi mac address, eas identifier and uan} under Admin -> Asset Additional Fields if not created.

    • In the Python file, search for "def convert_data_to_sdp_asset_json". meta_info will be found below the line. i.e,

    • make a api call for "/api/v3/assets/_metainfo".

    • In the response, search of "udf_fields", it should look something like that

    • From the response, replace the udf field names with the one from the api response. for example, in this case, python file last_connected_time is mapped with "udf_sline_902" but according to the api response, my api key for LAST CONNECTED TIME is udf_sline_301. so I would replace it and my meta data would look like this.

       meta_info = { 
       "last_connected_time": "udf_sline_902", 
       ... 
       }  

    • Note: for versions above 15100/7700 , please make sure to include them by drag and drop these additional field under Asset product type fields (Admin -> Asset Management -> Product Type)






Step 3: Execution  

After completing the configuration, run the script using one of the following commands:

 python SyncIntuneToSDP.py
# or
python3 SyncIntuneToSDP.py 

Ensure the script is run from its directory.


How to Schedule in Custom Script :-

1. Admin -> Custom Schedules
2. Choose Execute Script as the Executor
3. Specify the fileName (i.e, SyncIntuneToSDP.py). make sure to place the file in the directory as mentioned in the Custom Schedule Page.
4. Choose the desired date and frequency