{ "definition": { "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", "contentVersion": "1.0.0.0", "triggers": { "Recurrence": { "type": "Recurrence", "description": "Runs everyday at 22.00", "recurrence": { "interval": 1, "frequency": "Day", "timeZone": "W. Europe Standard Time", "schedule": { "hours": [ 22 ] } } } }, "actions": { "Scope_-_Error_Notification": { "type": "Scope", "actions": { "For_each": { "type": "Foreach", "description": "For each group id ", "foreach": "@variables('GroupTagPairs')", "actions": { "Compose_-_GroupID": { "type": "Compose", "inputs": "@items('For_each')?['groupId']" }, "Until": { "type": "Until", "expression": "@equals(variables('NextLinkUri'),'Completed')", "limit": { "count": 60, "timeout": "PT1H" }, "actions": { "HTTP_-_Get_Devices": { "type": "Http", "inputs": { "uri": "@variables('NextLinkUri')", "method": "GET", "authentication": { "audience": "https://graph.microsoft.com", "type": "ManagedServiceIdentity" } }, "runAfter": { "Compose_-_NextLinkUri_Pagination": [ "Succeeded" ] } }, "Parse_JSON_-_Devices": { "type": "ParseJson", "inputs": { "content": "@body('HTTP_-_Get_Devices')", "schema": { "properties": { "@@odata.context": { "type": [ "string", "null" ] }, "value": { "items": { "properties": { "@@odata.type": { "type": [ "string", "null" ] }, "accountEnabled": { "type": [ "boolean", "null" ] }, "alternativeSecurityIds": { "items": { "properties": { "identityProvider": {}, "key": { "type": [ "string", "null" ] }, "type": { "type": [ "integer", "null" ] } }, "required": [ "type", "identityProvider", "key" ], "type": "object" }, "type": "array" }, "approximateLastSignInDateTime": { "type": [ "string", "null" ] }, "complianceExpirationDateTime": {}, "createdDateTime": { "type": [ "string", "null" ] }, "deletedDateTime": {}, "deviceCategory": {}, "deviceId": { "type": [ "string", "null" ] }, "deviceMetadata": {}, "deviceOwnership": { "type": [ "string", "null" ] }, "deviceVersion": { "type": [ "integer", "null" ] }, "displayName": { "type": [ "string", "null" ] }, "domainName": {}, "enrollmentProfileName": { "type": [ "string", "null" ] }, "enrollmentType": { "type": [ "string", "null" ] }, "extensionAttributes": { "properties": { "extensionAttribute1": {}, "extensionAttribute10": {}, "extensionAttribute11": {}, "extensionAttribute12": {}, "extensionAttribute13": {}, "extensionAttribute14": {}, "extensionAttribute15": {}, "extensionAttribute2": {}, "extensionAttribute3": {}, "extensionAttribute4": {}, "extensionAttribute5": {}, "extensionAttribute6": {}, "extensionAttribute7": {}, "extensionAttribute8": {}, "extensionAttribute9": {} }, "type": "object" }, "externalSourceName": {}, "id": { "type": [ "string", "null" ] }, "isCompliant": { "type": [ "boolean", "null" ] }, "isManaged": { "type": [ "boolean", "null" ] }, "isRooted": { "type": [ "boolean", "null" ] }, "managementType": { "type": [ "string", "null" ] }, "manufacturer": { "type": [ "string", "null" ] }, "mdmAppId": { "type": [ "string", "null" ] }, "model": { "type": [ "string", "null" ] }, "onPremisesLastSyncDateTime": {}, "onPremisesSyncEnabled": {}, "operatingSystem": { "type": [ "string", "null" ] }, "operatingSystemVersion": { "type": [ "string", "null" ] }, "physicalIds": { "items": { "type": [ "string", "null" ] }, "type": "array" }, "profileType": { "type": [ "string", "null" ] }, "registrationDateTime": { "type": [ "string", "null" ] }, "sourceType": {}, "systemLabels": { "type": "array" }, "trustType": { "type": [ "string", "null" ] } }, "required": [ "@@odata.type", "id", "deletedDateTime", "accountEnabled", "approximateLastSignInDateTime", "complianceExpirationDateTime", "createdDateTime", "deviceCategory", "deviceId", "deviceMetadata", "deviceOwnership", "deviceVersion", "displayName", "domainName", "enrollmentProfileName", "enrollmentType", "externalSourceName", "isCompliant", "isManaged", "isRooted", "managementType", "manufacturer", "mdmAppId", "model", "onPremisesLastSyncDateTime", "onPremisesSyncEnabled", "operatingSystem", "operatingSystemVersion", "physicalIds", "profileType", "registrationDateTime", "sourceType", "systemLabels", "trustType", "extensionAttributes", "alternativeSecurityIds" ], "type": "object" }, "type": "array" } }, "type": "object" } }, "runAfter": { "Check_if_odata.nextLink_is_empty": [ "Succeeded" ] } }, "Union_DeviceArray": { "type": "Compose", "inputs": "@union(variables('DeviceArray'),body('HTTP_-_Get_Devices')?['value'])", "runAfter": { "HTTP_-_Get_Devices": [ "Succeeded" ] } }, "Set_variable_-_DeviceArray": { "type": "SetVariable", "inputs": { "name": "DeviceArray", "value": "@outputs('Union_DeviceArray')" }, "runAfter": { "Union_DeviceArray": [ "Succeeded" ] } }, "Check_if_odata.nextLink_is_empty": { "type": "If", "description": "Pagination check, loop until no more pages available", "expression": { "and": [ { "equals": [ "@empty(body('HTTP_-_Get_Devices')?['@odata.nextLink'])", "@true" ] } ] }, "actions": { "Set_variable_2": { "type": "SetVariable", "inputs": { "name": "NextLinkUri", "value": "Completed" } } }, "else": { "actions": { "Set_variable_3": { "type": "SetVariable", "inputs": { "name": "NextLinkUri", "value": "@body('HTTP_-_Get_Devices')?['@odata.nextLink']" } } } }, "runAfter": { "Set_variable_-_DeviceArray": [ "Succeeded" ] } }, "Compose_-_NextLinkUri_Pagination": { "type": "Compose", "inputs": "@variables('NextLinkUri')" }, "Filter_array": { "type": "Query", "description": "Filter out device that has no tag or are tagged incorrectly", "inputs": { "from": "@body('Parse_JSON_-_Devices')?['value']", "where": "@or(\n empty(item()?['extensionAttributes']?['extensionAttribute15']),\n not(equals(item()?['extensionAttributes']?['extensionAttribute15'], outputs('Compose_-_tagValue')))\n)\n" }, "runAfter": { "Parse_JSON_-_Devices": [ "Succeeded" ] } }, "For_each_-_Add_tag_to_device": { "type": "Foreach", "foreach": "@outputs('Filter_array')['body']", "actions": { "Compose_-_id": { "type": "Compose", "description": "Azure device id", "inputs": "@item()?['id']" }, "Compose_-_Tag": { "type": "Compose", "description": "Displays the tag being applied to the device", "inputs": "@outputs('Compose_-_tagValue')", "runAfter": { "Compose_-_id": [ "Succeeded" ] } }, "HTTP_-_Update_ExtensionAttribute15": { "type": "Http", "description": "Updates ExtensionAttribute15 on the device", "inputs": { "uri": "https://graph.microsoft.com/v1.0/devices/@{outputs('Compose_-_id')}", "method": "PATCH", "headers": { "Content-type": "application/json" }, "body": { "extensionAttributes": { "extensionAttribute15": "@{outputs('Compose_-_Tag')}" } }, "authentication": { "audience": "https://graph.microsoft.com", "type": "ManagedServiceIdentity" } }, "runAfter": { "Compose_-_Tag": [ "Succeeded" ] } } }, "runAfter": { "Filter_array": [ "Succeeded" ] }, "runtimeConfiguration": { "concurrency": { "repetitions": 1 } } } }, "runAfter": { "Set_variable_-_DeviceArray_to_empty": [ "Succeeded" ] } }, "Set_variable_-_NextLinkUri": { "type": "SetVariable", "inputs": { "name": "NextLinkUri", "value": "https://graph.microsoft.com/v1.0/groups/@{outputs('Compose_-_GroupID')}/members" }, "runAfter": { "Compose_-_tagValue": [ "Succeeded" ] } }, "Set_variable_-_DeviceArray_to_empty": { "type": "SetVariable", "inputs": { "name": "DeviceArray", "value": [] }, "runAfter": { "Set_variable_-_NextLinkUri": [ "Succeeded" ] } }, "Compose_-_tagValue": { "type": "Compose", "inputs": "@items('For_each')?['tagValue']", "runAfter": { "Compose_-_GroupID": [ "Succeeded" ] } } }, "runtimeConfiguration": { "concurrency": { "repetitions": 1 } } } }, "runAfter": { "Initialize_variable_-_Array_-_DeviceArray": [ "Succeeded" ] } }, "Initialize_variables_-_GroupTagPairs": { "type": "InitializeVariable", "inputs": { "variables": [ { "name": "GroupTagPairs", "type": "array", "value": [ { "groupId": "ce391da0-cf77-4d71-bbf2-EXAMPEL", "tagValue": "YourTag1" }, { "groupId": "GroupObjectID", "tagValue": "YourTag2" }, { "groupId": "GroupObjectID", "tagValue": "YourTag3" }, { "groupId": "GroupObjectID", "tagValue": "YourTag4" } ] } ] }, "runAfter": {} }, "Initialize_variable_-_String_-_NextLinkUri": { "type": "InitializeVariable", "inputs": { "variables": [ { "name": "NextLinkUri", "type": "string" } ] }, "runAfter": { "Initialize_variables_-_GroupTagPairs": [ "Succeeded" ] } }, "Initialize_variable_-_Array_-_DeviceArray": { "type": "InitializeVariable", "inputs": { "variables": [ { "name": "DeviceArray", "type": "array" } ] }, "runAfter": { "Initialize_variable_-_String_-_NextLinkUri": [ "Succeeded" ] } } }, "outputs": {}, "parameters": { "$connections": { "type": "Object", "defaultValue": {} } } }, "parameters": { "$connections": { "type": "Object", "value": {} } } }