Follow the steps in this blog to seamlessly rename your Intune devices, appending the primary assigned user’s UPN along with a random suffix.

I’ve created this Logic App that renames the devices as the Intune options are limited to the serial number and random generated values. Both are not easy to work with. I’ve chosen a random GUID, as some devices have serial numbers such as “0”, “DefaultString” or “ToBeFilledByOEM”.

This logic app will rename devices to PREFIX-UPN+RANDOM. There is a 15 character device name limit, because of this the UPN is stripped, and the prefix should be 3 characters max.

You will need an Azure Subscription, and an Logic App. In this blog, I assume you already have these.

Azure AD Application Registration

Start with creating an Azure AD Application Registration in the Azure AD portal and take note of the Application ID and Tenant ID.

Next, create a new Client secret, and take note of the Value for later use.

Finally, add the API permissions required to rename the devices.

Azure Logic App

Assuming you’ve already created a Logic App, start with a blank app, and a Recurrence trigger. I would recommend to change the names of the action blocks to the same as in the screenshots, this will make things easier in the next steps.

This HTTP action requests all device information, fill the details from the app registration in the green squares.

Next, we parse the JSON information that we’ve just received from the Graph action.

Use this schema:

{
    "properties": {
        "@@odata.context": {
            "type": "string"
        },
        "@@odata.count": {
            "type": "integer"
        },
        "value": {
            "items": {
                "properties": {
                    "azureADDeviceId": {
                        "type": "string"
                    },
                    "deviceEnrollmentType": {
                        "type": "string"
                    },
                    "deviceName": {
                        "type": "string"
                    },
                    "enrolledDateTime": {
                        "type": "string"
                    },
                    "id": {
                        "type": "string"
                    },
                    "lastSyncDateTime": {
                        "type": "string"
                    },
                    "managedDeviceOwnerType": {
                        "type": "string"
                    },
                    "operatingSystem": {
                        "type": "string"
                    },
                    "serialNumber": {
                        "type": "string"
                    },
                    "userId": {
                        "type": "string"
                    },
                    "userPrincipalName": {
                        "type": "string"
                    }
                },
                "required": [
                    "id",
                    "userId",
                    "deviceName",
                    "managedDeviceOwnerType",
                    "enrolledDateTime",
                    "lastSyncDateTime",
                    "operatingSystem",
                    "deviceEnrollmentType",
                    "azureADDeviceId",
                    "userPrincipalName",
                    "serialNumber"
                ],
                "type": "object"
            },
            "type": "array"
        }
    },
    "type": "object"
}

Next up, there are some Compose Data actions to get the UPN stripped to max 8 characters, and create a random GUID of max 4 characters. Combined with the prefix, this will become the new device name.

Start with the Compose UPN action, the For each will auto populate.

Below the details of the inputs:

items('For_each')?['userPrincipalName']

split(outputs('UPN'),'@')

toUpper(slice(string(outputs('User')[0]),0,7))

toUpper(slice(guid(),1,4))

outputs('PREFIX') - outputs('User-MAX') outputs('GUID-MAX')

Add these last values without any spaces

Finally, create a condition where we verify if the device name is not already matching the the user’s upn, and exclude certain computernames from the action. In this block, you can also add an deviceid you want to test with.

The first Output is the dynamic content from the stripped UPN.
Finally, add an HTTP action, which renames the device.

All Done!

When you run the Logic App, it should rename the devices to the new naming convention. Of course, it is recommended to run it on a single computer first to validate your configuration, you can do this by adding an extra validation in the condition block.

Categories:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *