Set up the missing naming convention to increment your AutoPilot device names

The purpose of this blog post is to inform you how to configure your AutoPilot naming convention with new variables like incrementing the device number.

I recently had a workshop about the design of AutoPilot. The naming convention of the device came up. By default, AutoPilot can only use the variables %SERIAL% and %RAND:x%. Some customers want to use other naming conventions than Microsoft supports with AutoPilot, for example, increase the device number like LPT-1 and LPT-2, etc. I decided to fix that missing feature. I have created a Microsoft List to inventory the AutoPilot device and a Logic app to automate the process.

Requirements:

  • Cloud Application Administrator
  • Global Administrator or Privileged Role Administrator

License Requirements:

  • Microsoft SharePoint
  • Microsoft Intune

Graph API Requirements:

  • DeviceManagementServiceConfig.Read.All
  • DeviceManagementServiceConfig.ReadWrite.All

What is Microsoft AutoPilot?

Windows Autopilot is a collection of technologies used to set up and pre-configure new devices or devices that have been reinstalled or reset and get ready for productive use. AutoPilot automates, changes, and adds screens in the OOBE phase and together with Microsoft Intune, you can give your devices directly to your end-users without the need to do manual tasks, build, maintain, or apply custom operating system images.

More information can be found here

What is Microsoft List?

Microsoft Lists is a Microsoft 365 application that allows you to create simple, intelligent, and flexible lists to help you to organize your work more effectively. Microsoft List is stored on a SharePoint Site and can also be included in Microsoft Teams. Microsoft List can also be used as a data source for automation. With ready-made templates, it is an easy and handy tool to use.

More information can be found here

What is an Azure Logic App?

Azure Logic Apps is a cloud service that helps you schedule, automate, and orchestrate tasks, business processes, and workflows when you need to integrate apps, data, systems, and services across enterprises or organizations. The UI of Azure Logic apps looks similar to PowerAutomate. But PowerAutomate and Azure Logic apps are not the same.

Check out the blog post of Thijs Lecomte to decide what you should use

More information about Azure Logic apps can be found here

How to configure the missing naming convention to increment your AutoPilot device names

Disclaimer

Don’t just use it in production environments. Please test it first in a test environment. The way it is configured is not officially supported!

Part 1 – Create App Registration

  • Click on + New registration
  • Configure an app name e.g., Naming Convention AutoPilot Devices
  • Click on the Register button, the app will be created and automatically opened.
  • In the menu click on API Permissions
  • Click on + Add a permission
  • Select Microsoft Graph and select Application permissions
  • Search and add the following permissions
DeviceManagementServiceConfig.Read.All
DeviceManagementServiceConfig.ReadWrite.All
  • Grant admin consent for your organization
  • In the menu click on Certificates & Secrets
  • Click on + New Client secret

  • Set a description and the expiry of the secret and click on Add
  • Copy the value of the secret, this is required in part 3
  • Go to the overview page and copy the Client ID and Tenant ID, those are also required in part 3

Part 2 – Create Microsoft List

  • Open portal.office.com
  • Click on the menu button
  • Click on SharePoint (if you are missing the SharePoint button click on all apps)
  • Open an existing SharePoint Site (if you do not have a site, create a site via the creating site button)
  • Click on + new button
  • Open the Asset Manager Template
  • Click on the Use Template button
  • Fill in a name and a Description for the Microsoft list.
  • Click on Create and your new Microsoft List is created.
  • Scroll to the last column and click on the + Add column.
    (If you want to hide columns click on Show/hide columns)
  • Click on Single line of text
  • Create the following columns
NameAutoPilot ID
Description
TypeSingle line of text
Default Value
NameGroupTag
Description
TypeSingle line of text
Default Value

Part 3 – Create Azure Logic App

Note. Rename every Azure Logic App action to match the screenshots!

  • Open portal.azure.com
  • Search for Logic App
  • Click on + Add
  • Select an existing Resource Group or create a new Resource Group
  • Select the instance Type (I have chosen for Consumption because it is cheaper to use and it’s only one flow. See Azure Calculator)
  • Select your region and click on Review + Create
  • Check the details on the Review + Create page and click on Create
  • After the deployment is completed, go to your new Logic App via Go to Resource button
  • The first step of the workflow is the Recurrence trigger, based on the desired interval
  • The next four steps of the workflow are to initialize variables.
Set PrefixSet Azure Tenant IDSet Authentication Client IDSet Authentication Secret
NamePrefixTenantIDClientIDSecret
TypeStringStringStringString
ValueE.G., LPT{Paste the Tenant ID that you have copied in part 1}{Paste the Client ID that you have copied in part 1}{Paste the secret that you have copied in part 1}
  • The next step is to get all AutoPilot devices via a HTTP Get request
MethodGet
Authentication TypeActive Directory OAuth
Tenant@{variables(‘TenantID’)}
Audiencehttps://graph.microsoft.com
Client ID@{variables(‘ClientID’)}
Credential TypeSecret
Secret@{variables(‘Secret’)}

URI:

https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeviceIdentities/
  • Now we must parse the returned Autopilot devices info into separate outputs.

Content: @{body(‘HTTP_Get_AutoPilot_Devices’)}

Schema:

{
    "type": "object",
    "properties": {
        "@@odata.context": {
            "type": "string"
        },
        "@@odata.count": {
            "type": "integer"
        },
        "value": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string"
                    },
                    "deploymentProfileAssignmentStatus": {
                        "type": "string"
                    },
                    "deploymentProfileAssignmentDetailedStatus": {
                        "type": "string"
                    },
                    "deploymentProfileAssignedDateTime": {
                        "type": "string"
                    },
                    "groupTag": {
                        "type": "string"
                    },
                    "purchaseOrderIdentifier": {
                        "type": "string"
                    },
                    "serialNumber": {
                        "type": "string"
                    },
                    "productKey": {
                        "type": "string"
                    },
                    "manufacturer": {
                        "type": "string"
                    },
                    "model": {
                        "type": "string"
                    },
                    "enrollmentState": {
                        "type": "string"
                    },
                    "lastContactedDateTime": {
                        "type": "string"
                    },
                    "addressableUserName": {
                        "type": "string"
                    },
                    "userPrincipalName": {
                        "type": "string"
                    },
                    "resourceName": {
                        "type": "string"
                    },
                    "skuNumber": {
                        "type": "string"
                    },
                    "systemFamily": {
                        "type": "string"
                    },
                    "azureActiveDirectoryDeviceId": {
                        "type": "string"
                    },
                    "azureAdDeviceId": {
                        "type": "string"
                    },
                    "managedDeviceId": {
                        "type": "string"
                    },
                    "displayName": {
                        "type": "string"
                    }
                },
                "required": [
                    "id",
                    "deploymentProfileAssignmentStatus",
                    "deploymentProfileAssignmentDetailedStatus",
                    "deploymentProfileAssignedDateTime",
                    "groupTag",
                    "purchaseOrderIdentifier",
                    "serialNumber",
                    "productKey",
                    "manufacturer",
                    "model",
                    "enrollmentState",
                    "lastContactedDateTime",
                    "addressableUserName",
                    "userPrincipalName",
                    "resourceName",
                    "skuNumber",
                    "systemFamily",
                    "azureActiveDirectoryDeviceId",
                    "azureAdDeviceId",
                    "managedDeviceId",
                    "displayName"
                ]
            }
        }
    }
}
  • The next step is to create three array variables
Initialize AutoPilot Device Serial Number VariableInitialize AutoPilot Device VariableInitialize Microsoft List Serial Number Variable
NameSerialNumberAutoPilotDeviceAutoPilotDeviceInfoSerialNumberMicrosoftList
TypeArrayArrayArray
  • Create a For each action with the Value output of the Parse JSON AutoPilot Devices step
  • Next step is to fill two variables. Create two append to array variable actions in the for each loop.
NameAutoPilot ID
Value@{items(‘Apply_to_each_AutoPilot_Device’)?[‘serialNumber’]}

Name: AutoPilotDeviceInfo

Value:

{
  "id": "@{items('Apply_to_each_AutoPilot_Device')?['id']}",
  "groupTag": "@{items('Apply_to_each_AutoPilot_Device')?['groupTag']}",
  "purchaseOrderIdentifier": "@{items('Apply_to_each_AutoPilot_Device')?['purchaseOrderIdentifier']}",
  "serialNumber": "@{items('Apply_to_each_AutoPilot_Device')?['serialNumber']}",
  "productKey": "@{items('Apply_to_each_AutoPilot_Device')?['productKey']}",
  "manufacturer": "@{items('Apply_to_each_AutoPilot_Device')?['manufacturer']}",
  "model": "@{items('Apply_to_each_AutoPilot_Device')?['model']}",
  "enrollmentState": "@{items('Apply_to_each_AutoPilot_Device')?['enrollmentState']}",
  "addressableUserName": "@{items('Apply_to_each_AutoPilot_Device')?['addressableUserName']}",
  "userPrincipalName": "@{items('Apply_to_each_AutoPilot_Device')?['userPrincipalName']}",
  "resourceName": "@{items('Apply_to_each_AutoPilot_Device')?['resourceName']}",
  "skuNumber": "@{items('Apply_to_each_AutoPilot_Device')?['skuNumber']}",
  "systemFamily": "@{items('Apply_to_each_AutoPilot_Device')?['systemFamily']}",
  "azureActiveDirectoryDeviceId": "@{items('Apply_to_each_AutoPilot_Device')?['azureActiveDirectoryDeviceId']}",
  "azureAdDeviceId": "@{items('Apply_to_each_AutoPilot_Device')?['azureAdDeviceId']}",
  "managedDeviceId": "@{items('Apply_to_each_AutoPilot_Device')?['managedDeviceId']}",
  "displayName": "@{items('Apply_to_each_AutoPilot_Device')?['displayName']}"
}
  • The next step is to get the Microsoft List items via Get items
  • Click on the Sign in button and login with an account that has read/write access to the Microsoft List you had created in Part 1.
    I have selected my admin account
  • Select the SharePoint List Site Address and the Microsoft List you have created in Part 1
  • Create again a For each loop and select the value output of the Get Microsoft List Device Items
  • Now it is time to fill the last array variable SerialNumberMicrosoftList with the Serial number value of the Microsoft List via an Append to array variable
  • Time to do some magic and compare both data sources.
  • Create a new step with a For each action, and select the SerialNumberAutoPilotDevice variable
  • Add the Condition action to the Apply to each AutoPilot Serial Number Variable loop.
  • Set the condition: SerialNumberMicrosoftList contains Apply to each AutoPilot Serial Number Variable -> Current item
  • For now, I only want an action when the AutoPilot device does not exist in the Microsoft List, so let the True part of the condition empty.
  • Configure the False part of the condition Check IF AutoPilot Serial Number Exist In Microsoft List
  • Create Filter array action. Set the following filter options
From@variables(‘AutoPilotDeviceInfo’)
Value@item()?[‘serialNumber’] Contains Apply to each AutoPilot Serial Number Variable -> Current item
  • Add Create Item action in the False part of the condition
  • Select the correct SharePoint Site Address and list name
  • Click on Add new parameter button and add the following parameters:
    • Manufacturer Value
    • Model
    • Serial Number
    • AutoPilot ID
    • GroupTag

 

  • Configure per parameter the following expression:
Title: 
body('Filter_New_AutoPilot_Device_Info_By_SerialNumber')?[0]?['displayname']

Manufacturer: 
body('Filter_New_AutoPilot_Device_Info_By_SerialNumber')?[0]?['manufacturer']

Model: 
body('Filter_New_AutoPilot_Device_Info_By_SerialNumber')?[0]?['model']

Serial number:
body('Filter_New_AutoPilot_Device_Info_By_SerialNumber')?[0]?['serialNumber']

AutoPilot ID:
body('Filter_New_AutoPilot_Device_Info_By_SerialNumber')?[0]?['id']

Grouptag:
body('Filter_New_AutoPilot_Device_Info_By_SerialNumber')?[0]?['groupTag']
  • Now it is time to set the correct name for the AutoPilot device based on the SharePoint List ID. Create an Update item
  • Select the Site Address and List name again.
  • Configure the ID property of the Create AutoPilot Device Item In Microsoft List:
@{outputs('Create_AutoPilot_Device_Item_In_Microsoft_List')?['body/ID']}
  • Configure the Title with:
@{variables('Prefix')}@{outputs('Create_AutoPilot_Device_Item_In_Microsoft_List')?['body/ID']}
  • The name is set correctly within Microsoft List and will be increased by one if a new device is added.
  • The next step is to create a JSON to set the new AutoPilot Device name. Create a Compose Set the following input code:
{
  "displayName": "@{outputs('Get_item_-_AutoPilot_Device_information_from_Microsoft_List')?['body/Title']}"
}
  • Let’s synchronize the Microsoft List with AutoPilot. Create a new HTTP action with following settings
MethodPOST
Body@{outputs(‘Compose_-_Prepare_AutoPilot_Device_JSON’)}
Authentication TypeActive Directory OAuth
Tenant@{variables(‘TenantID’)}
Audiencehttps://graph.microsoft.com
Client ID@{variables(‘ClientID’)}
Credential TypeSecret
Secret@{variables(‘Secret’)}

URI:

https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeviceIdentities/@{outputs('Set_Device_Name_For_New_AutoPilot_Device')?['body/AutoPilotID']}/updateDeviceProperties
  • Save the Logic App and Click on Run Trigger

Entire Azure Logic App flow

Results

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published.

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