Renaming Teamviewer portal devices with the primary user from Intune

PowerShell script with functions that append the devices' [primary user] (retrieved from Intune) to the device name in the Teamviewer portal

Posted on 30 July, 2019

PowerShell script with functions that append the devices’ [primary user](retrieved from Intune) to the device name in the Teamviewer portal.

TeamViewer Portal

By default, when a device is registered in the TeamViewer portal by deploying the msi (through Intune of course) it doesn’t contain any information regarding the primary (or any other) user of the device. Generally, the end user will not know the name of their device and the IT Service Desk would prefer to search by the users’ name rather than device.

By scheduling an Azure Automation script that uses the TeamViewer and Intune Graph API, we can append a [UserName] to the device so it looks like: Lap-Win10-1[JackRudlin]

See below on how to set things up.

TeamViewer token

To connect to the TeamViewer API and add the primary user to the existing device name, we need a token to authenticate.

Login to the TeamViewer portal with an admin account that will remain active - maybe a generic super user? In my example I’m using an admin account with my name.

You have to create a token under a user account, rather than the company profile, because only user accounts have access to edit devices via the API.

Edit your account profile in the top right drop down menu:

Create a new script token from the Apps menu:

Give the token a name, description and edit access to Computers:

Make a note of the token - however it can always be retrieved later by editing the token:

Variables

Replace $IntuneROAccount with the name of the Azure Automation Account credentials that will provide RO access to Intune.

You don’t have to, but if you want to change the format of how the user names will appear and how its matched by the script, change the $NamingPatternMatch variable and also the [$PrimaryUser] on line 141.

$NamingPatternMatch='\[(.+)\]'[$PrimaryUser]

Output

During the script run, output will look like this if running from Azure Automation: