Microsoft intune spoke

Nishchitha K S
Tera Guru

OMG!!!! The Service Graph Connector for Microsoft Intune is licensed! 
How will I bring intune devices into Servicenow 🤔

💡Here's how you can, if your system already has 'IntegrationHub' subscription:

Below are the steps to bring Managed devices into your ServiceNow instance
STEPS: 
1. Navigate> Plugins> Install 'Microsoft Intune Spoke [sn_ms_intune_spoke]
2. Switch application to 'Microsoft Intune Spoke' after installing
3. Navigate to Integration Hub > Credentials
     Create New: 
        Name: Give name of your choice [For eg., MS Intune Creds]
        Active: True
        Oauth Entity Profile : Microsoft Intune [Create new if oauth profile doesn't exists] 
                     Details for oauth entity profile creation: 
                        Name: Microsoft Intune
                        Oauth Provider: Microsoft Intune platform [Please request Client ID, Client Secret, Tenant from intune                                                      end and create oauth registry using Navigate> Application registry] 
                        Grant Type: Client credentials
                        Is default: True
                        Oauth Entity Profile Scopes: 

                             Oauth Entity Scope: Microsoft Graph Entity Scope
                             Oauth Scope: https://graph.microsoft.com/.default 
          After attaching entity profile click on 'Get OAuth Token' UI Link in Credential record

4. Navigate> > IntegrationHub>Connections & Credentials
    Create new: 
          Name: Microsoft_Intune [Name of your choice] 
          Type: Connection & Credential
          Connection Type: HTTP
          Click 'Save'
5. In Related List> Connections> Create new: 
           Name: Give name of your choice [For eg., MS_Intune_Connection] 
           Credentials: Attach creds created from Step 3 [MS Intune Creds] 
           Connection Alias: Attach connection created from Step 4 [MS_Intune_Connection] 
           Connection URL: https://graph.microsoft.com
           Attributes> Version [beta]

       
6. Navigate> Flow designer> Action
    Create new Action: 
     Name: Give name of your choice [For eg., Look up Intune Managed Devices]
     Step A: 
        Inputs:  Filtering On [Type: choice], Filter Value [Type: String]
     Step B:     
        Action Preprocessing: Enable preprocessing script: True

     Step C:    
       Pre Processing Script: Pass the Input Variables from Step A
      Script: Sample script
                 

        (function execute(inputs, outputs) {
                inputs = new MicrosoftIntuneUtils().trimStringInputs(inputs);
                if (inputs.filtering_on == "None")
                  outputs.filter = null;
               else {
                   if (inputs.filtering_on == "managedDeviceOwnerType" ||
                   inputs.filtering_on == "deviceRegistrationState" ||
                   inputs.filtering_on == "complianceState" || inputs.filtering_on == "serialNumber")
                   outputs.filter = inputs.filtering_on + " eq '" + inputs.filter_value + "'";
              else if (inputs.filtering_on == "Serial Number")
                   outputs.filter = 'serialNumber' + " eq '" + inputs.filter_value + "'";
              else
                    outputs.filter = "contains(" + inputs.filtering_on + ",'" + inputs.filter_value + "')";
                }})(inputs, outputs);


      Step D : 
         Request: How will you get data: REST Step
                         Enable pagination: True
      Step E: 
          Pagination Setup Step
                       Pagination variables: 
                            i) Name: getNextPage   
                               Initial Value: false
                               Next Value from: Script
                           ii) Name: odatanextlink   
                               Initial Value: 
                               Next Value from: Response Body
                          iii) Name: skipToken   
                               Initial Value: 
                               Next Value from: Script
            Pagination variables Script: 
                     
(function paginate(variables, pageResponse) {
                        try {

                          var odata_nextlink = variables.odatanextlink;

                          var next_link = JSON.stringify(odata_nextlink);
                           if (next_link != '') {
                                variables.getNextPage = true;
                                variables.skipToken = odata_nextlink.split('$skiptoken=')[1];
                          } else {
                                variables.getNextPage = false;
                          }
                        } catch (err) {
                            variables.getNextPage = false;
                     }})(variables, pageResponse);

     Step F: 
        REST Step :
                Look up Managed Devices:
             Connection Details: 

                 Connection: Use Connection Alias
                 Connection Alias: Attach connection created from Step 4 [MS_Intune_Connection]   (Use ID of connection)
                 Base URL: https://graph.microsoft.com/beta 
            Request Details: 
                 Build Request: Manually

                 Resource Path: /deviceManagement/managedDevices    (Confirm with Intune) 
                 HTTP Method: GET
           Query Parameteres:

                Name:  $top              Value: 500
                Name:  $skiptoken    Value: Input from Step E  >Skip token
                Name:  $filter             Value: Input from Step C > Filter 
     Step G: 

               How will you identify each record: JSON/XML Splitter
               How will you parse each item into object: Script Parser
     Step H: 
         Splitter Step: 
                Source Format: JSON
                Item Path: $.value
     Step I: 
          Script Parser Step: 

                 Sample script:                         

                         (function parse(inputs, outputs) {
                              var item = JSON.parse(inputs.sourceItem);
                              outputs.targetObject = item;
                         })(inputs, outputs)


7. Navigate> System Import sets> Data Sources
8. Create new Data source: 
     Name: Give name of your choice [For eg., Intune Managed Devices]
     Import set label : Staging table name you want devices to be loaded [ For eg., Intune Managed Devices] 
     Import set name: u_intune_managed_devices [backend name of staging table]
     Type: Data stream (IntegrationHub)   
     Data in single column: uncheck
     Use Batch import: uncheck
     Data Steam action: Select the action created in Step 6 [Look up Intune Managed Devices]
Data Stream action inputs
    Filtering on: select values in dropdown based on your data to be filtered and bought into servicenow. I kept as                                     none since no filtering was required.
    Filter Value: Value of the filter selected (For eg., If selected Operating System the value is Windows)

    
Click on load all records [Test load before full load]

9. Create transform map
     Name: Give name of your choice 
     Source table: Fetch from Step 8: u_intune_managed_devices [Staging table]
     Target table: Computer [cmdb_ci_computer]
     Script:        

        runIt();
       function runIt() {
            validateImpFields();
            setMakeAndModel();
       }
      function setMakeAndModel() {
           var mm = MakeAndModelJS.fromNames(source.u_manufacturer, source.u_model, "hardware");
           target.model_id = mm.getModelNameSysID();
           target.manufacturer = mm.getManufacturerSysID();
      }
     function validateImpFields() {
          if (JSUTIL.nil(source.u_serialnumber) || source.u_serialnumber == "unknown") {
          ignore = true;
         log.error("Serial Number Cannot be empty or Unknown and the ID is " + source.u_id);
     } else if (JSUTIL.nil(source.u_model) || source.u_model == "unknown") {
        ignore = true;
        log.error("Model ID Cannot be empty or Unknown for serial number " + source.u_serialnumber + " and the ID is " + source.u_id);
     }
   }
    target.discovery_source = "Intune-Spoke";


Map fields using Field map

10. Navigate> Computer[cmdb_ci_computer]> Open dictionary entry for 'Discovery source' field
       Create new choice: Intune-Spoke [If choice doesn't exists]
11. Navigate> Scheduled Data import

       Create new: Microsoft Intune Managed Devices import
       Data source Attach data source created in Step 8: Intune Managed Devices
       Run As: System Admin
       Run: Daily
  Configure schedule import as required. 


Please help like and mark helpful if the post did benefit you 🙂
Happy Learning!!!!!




1 REPLY 1

Jason S1
Tera Contributor

Hello, great writeup! I'm doing something similar. For the pagination, you are getting odatanextlink from the response body, can you share what you put in the "Expression" field?