PowerShell script with functions that append the devices’ [primary user] (retrieved from Intune) to the device name in the 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
[User Name] to the device so it looks like:
Lap-Win10-1 [Jack Rudlin]
See below on how to set things up.
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:
The script relies on PowerShell module Microsoft.Graph.Intune so make sure that’s installed in your Azure Automation account and is running at least module version 6.1907.1.
Note: There is a bug with older versions of the Microsoft.Graph.Intune module in Azure Automation Accounts. More details here.
Use an account or AAD Application that has read-only access to Intune device properties. See below for variables to amend.
$token variable with the TeamViewer token that you created above.
#Define Auth Token for TeamViewer $token = "3462611-habtKKAf1VrtYJD2UWZO"
$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]
During the script run, output will look like this if running from Azure Automation:
Or this from a shell:
true is returned when a TeamViewer device is succesfully renamed.
The result looks like this from the TeamViewer portal:
and allows simple search by users name from the bar in the top right: