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 via Parse JSON function

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 via Initialize variable operation
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.
NameSerialNumberAutoPilotDevice
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 outside the For Each Loop.
  • 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 same Site Address and List name.
  • Configure the ID property of the Create AutoPilot Device Item In Microsoft List action:
@{body('Create_AutoPilot_Device_Item_In_Microsoft_List')?['ID']}
  • Configure the Title with:
@{variables('Prefix')}@{body('Create_AutoPilot_Device_Item_In_Microsoft_List')?['ID']}
  • The name is set correctly within Microsoft List and will be increased by one if a new device is added.
  • Let’s synchronize the Microsoft List with AutoPilot. Create a new HTTP action with following settings
MethodPOST
Body{
“displayName”: @{body(‘Set_Device_Name_For_New_AutoPilot_Device’)[‘Title’]}
}
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/@{body('Set_Device_Name_For_New_AutoPilot_Device')?['AutoPilotID']}/updateDeviceProperties
  • Save the Logic App and Click on Run Trigger

Entire Azure Logic App flow

Results

13 replies
  1. Maccoy
    Maccoy says:

    Great blog you have here! Can I check with you does this support Hybrid azure ad joined devices?

    Reply
    • René Laas
      René Laas says:

      Hi Maccoy,

      First, my advice is switch to AAD joined device. With the right setup you can reach your onprem resources. but I don’t know your configuration. But most of the time it is possible.

      Let’s go to the answer of your question.

      Hybrid AD Joined is using another method to enroll, it is not using the AutoPilot profile but a device configuration profile. so this means it is not possible via that way.

      But their are other ways to fix your problem, If all your device are listed in MS list, you are able to built a flow that renames the device to the name in SP List.

      If needed I can spend some time to figure it out and write a blog post about it. please let me know.

      Kind regards,

      Rene

      Reply
      • Maccoy
        Maccoy says:

        Hi Rene,
        Sure, if you have the time to figure it out and post it as a blog that would really be great. Really appreciate your time in helping out.

        Kind regards,

        Maccoy

        Reply
  2. Victor Yana
    Victor Yana says:

    Hi Rene, great blog you have here. May I know if it is possible to input the names and serial numbers in the sharepoint list and ask the logic apps to use the names provided in the list. Because our current inventory we are assigning name tags to the devices manually.

    Reply
  3. Anonymous PillowCase
    Anonymous PillowCase says:

    Hello, René

    Thank you from me also for posting the instructions.

    But I would like to see the code also.
    It’s my very first and I’m having a problem with “Check if AutoPilot Serial Number Exist In Microsoft List”
    I think that the problem is over there because it’s always False and I have the same device with different names in Asset Manager.

    And can you tell me how to write the prefix if I want the devices be named like this:
    Device-001
    Device-002

    Device-010
    Device-011

    Device-100
    Device-101

    Device-112

    Reply
    • René Laas
      René Laas says:

      Hi,

      to get the naming convention with 3 numbers like 101 you could use the Formatnumber expression. So set the following code in the Title field of the Set Device Name For New AutoPilot Device action

      @{variables('Prefix')}@{formatNumber(body('Create_AutoPilot_Device_Item_In_Microsoft_List')?['ID'],'000','en-us')}

      Did you set the @variables(‘SerialNumberAutoPilotDevice’) as the input for the Apply to each AutoPilot Serial Number Variable loop and set the condition to @variables(‘SerialNumberMicrosoftList’) contains @items(‘Apply_to_each_AutoPilot_Serial_Number_Variable’) = [current item].

      If the condition is always false, can you create before the condition a compose action with both variables to check if both are filled with data?
      To be sure you don’t have any item listed in your Ms list? and you have an AutoPilot device in your tenant registered?

      Kind regards,

      Rene

      Reply
  4. Richard
    Richard says:

    Hi.
    Your Instructions state.
    ” 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.
    Name AutoPilot ID Value @{items(‘Apply_to_each_AutoPilot_Device’)?[‘serialNumber’]}

    The Array does Not allow selection of AutoPilot ID Value. Dropdown list is only the three previous steps ( SerialNumberMicrosoftList, AutoPilotDeviceInfo, & SerialNumberAutoPilotDevice )

    Please help.

    Richard

    Reply
    • René Laas
      René Laas says:

      Hi Richard,

      I am sorry, I changed some actions in my flow and I didn’t update that one. You should use SerialNumberAutoPilotDevice. I have updated my blog and created my Logic app again. I will send you the code via the e-mail and a print screen of all the actions.

      Kind regards,

      Rene

      Reply
  5. Richard
    Richard says:

    Sorry. Still not clear on the steps. Can you reach out to me via email ? I can send you the screen grabs of the steps where it is confusing Thanks so much for your help

    Reply
  6. Richard
    Richard says:

    Hi. Thanks for taking the effort to posting instructions. I got to the end of the parse json section and it returns the results. However the instructions aren’t that clear for the next steps. Are they out of order ? or could you please post more detailed instructions for each step ? Or a youtube video ? Please & thank you

    Reply
    • René Laas
      René Laas says:

      Hi Richard,

      Happy to help. Sorry that it was not clear enough. I had changed my flow and forget to update all the actions and images, now it up to date. Hopefully it is now more clear and you can forget the compose action that is not needed anymore.

      Please let me know if you need any help.

      Kind regards,

      Rene

      Reply

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.