I have been using Teamviewer for years I finally found a way to solve an old problem that had been bugging me for years. I am posting this here as I am sure this will benefit others.
Basically, we have 4000-5000 computers in our Computers & Contacts list, across various clients that we provide IT support for - We typically deploy Teamviewer through Group Policy / with a "Design & Deploy" MSI . This method when done correctly automatically adds the computer to the Contact List in the Group we want.
We then typically rename the contacts with perhaps the users name, or whatever - but over time, users change, and this information becomes old, and we end up with a mess in the contact list.
Another thing that bugs me, is that computers sometimes end up in the wrong group.
I discovered the Teamviewer API the other day, and started messing about with it, and wrote a few scripts in powershell which solves the above two issues by updating the Contact in the Computers and Contact List with the format "COMPUTERNAME (username) (Full Name)"
The API documentation is here: https://dl.tvcdn.de/integrate/TeamViewer_API_Documentation.pdf
The method consists of:
1) A Group Policy User Logon Script to generate a file on a file share which contains the Teamviewer ID, username and Full Name
2) A Scheduled Task which runs a batch file, which combines all the generated files into a powershell script, which is then run. It uses the Teamviewer API to update your Computers and Contacts list. The script looks to see if there are any updates to make, and if there are none, it simply ends. However, if there are updates to be made, it will continue and run the process.
A few points to make before we get into it (Surgeons General Health Warning)
1. I will say from the outset, that I am not an expert on Powershell Scripting - and these scripts have no error checking (not that it really needs it, it either works, or it doesnt!)
2. The API Token is stored in plain text, however, the script which runs the API commands is not and should not be visible to your end users. Obviously this is a fairly sensitive piece of information, so be sure to keep it safe and secure.
3. This is my own convoluted way of doing it, and I am welcome to any ideas or suggestions from those here with ideas or better scripting knowledge.
4. My scheduled task runs every minute - however, please be sure to read the API documentation, and note in particular the section about Rate Limits on Page 10. I am using Teamviewer Corporate, so its fine for me, but might not be fine for you if you're on a Free license for example. Just something to consider when creating your Scheduled Task later.
With the above out of the way, here goes.
Step 1 - Obtain / Create an API Token
1. Log into Teamviewer Management Console https://login.teamviewer.com
2. Click on your Login Name / Avatar at the top right hand side and select Edit Profile
3. Click on Apps
4. Create Script Token.
Description: API Key for updating ComputerList
Group Management: View
Computer & Contacts: View, add, edit & delete
Leave the rest as default (No Access)
5. Save it, and make a note of the API Token - you'll need it later.
Step 2 - Set up the folder structure for your scripts and put files in place.
Note: For simplicity, im going to use C:\TVUpdate - you can modify this to suit your own setup.
1. Download the RAR file containing the powershell scripts from (https://mega.nz/#!f2IBECKC!oGcYbcqd1ESHuBopRRqj2oGN740g8P1aUhR9o3EmuNo)
2. From the RAR, extract the contents so that the RAR contents are in C:\TVUpdate
The RAR contains 5 files & 1 folder.
- README.TXT (Read this!)
- RetrieveGroupsInfo.ps1 (This connects to Teamviewer via the API and creates a CSV of all your groups, and their Group IDs)
- RetrieveTVInfo.ps1 (This connects to Teamviewer, and create a Global Powershell variable containing literally all of the information from Computers & Contacts)
- UpdateTeamviewerDevice.ps1 (This, when fed parameters, updates a specific device with a new Alias, and Group ID)
- Run.bat (This is the file which runs on a schedule which kicks off the whole process)
- TV (This is the folder you're going to share, for the Logon Script to dump its instructions into)
3. Share the folder "C:\TVUpdate\TV" with the sharename "\\SERVERNAME\TV$"
(I like to use the $ to keep the share hidden)
4. Ensure that the Share Permissions are "Everyone - Full Control"
5. Ensure that the NTFS Permissions are "Everyone - Full Control"
6. Edit the 3x Powershell files and replace "INSERT_TOKEN_HERE" with your API Key.
Step 3 - Determine the correct Group ID, and update the script to use it.
1. Right Click on "RetrieveGroupsInfo.ps1" and run it.
All going well, groups.csv should open in notepad with a list of groups, and their "group_id" -
2. Find and make a note of the Group ID you want use.
3. Edit the file "UpdateTeamviewerDevice.ps1" and replace the text "INSERT_GROUPID_HERE" with the ID you made a note of (e.g. g92342)
Step 4 - Create the Group Policy Logon Script
1. Open up Group Policy Management and create a new GPO in the OU containing your Users.
2. Call it "Update Teamviewer Contacts" or whatever.
3. Edit it, and navigate to User Configuration -> Policies -> Windows Settings -> Scripts (Logon/Logoff)
4. Double Click on Logon
5. Switch to the Powershell Scripts Tab! (easy to miss this one)
6. Click Add
Script Name: \\servername\tv$\CreateUpdateFile.ps1
Script Parameters: \\servername\tv$\
(N.B. Make sure you include the backslash at the end)
7. Click Ok, and Ok again.
Now when users log on, the script will create e.g. (\\servername\tv$\6868686.bat)
Step 5 - Schedule the Task to Run every minute.
It's in the README.txt, but I use the following command, to schedule it under the logged in user, you may prefer to create a dedicated service account for it. This is up to yourself.
schtasks /create /sc minute /mo 1 /tn "Update Teamviewer Contacts" /tr c:\TVUpdate\run.bat /RU %USERNAME% /RP
That's it! Run gpupdate /force on a client computer, log off and on again, and watch as the entry on "Computers & Contacts" magically updates itself.
Hope this helps, let me know how you get on with it!
Denis Mc Auliffe
Systems Engineer @ Everything IT
One thing I just noticed, is that within "run.bat" the path c:\TVUpdate is hard coded. You might need to update that if you decide to put it on a different drive letter or path.
First impressions; it works, but some observations below:
Will report back any further observations, but so far it's looking very good.
I was beginning to wonder if anyone would ever actually try this out!
You're right, it's a pity the functionality is not built into Teamviewer - since using this, it has made my life so much easier.
I have it running on Server 2012 R2 and above - I havent tried it on any 2008/2008 R2 servers but your theory is probably correct on that one about the Powershell Versions.
I have also since had to make some minor changes to locate the Teamviewer ID from the WOW6432Node for 32 bit machines.
It's a bit rough, but it works!
I am glad it's working out for you :)
It's working out, but a few more comments after initial testing.
We have used this successfully with some minor additions:
It's not perfect, but works okay. A big thanks to Denis for the original work and scripts!
Im not really sure what you're asking? I havent updated the scripts much since I originally posted them as they're working.
Are you having difficulty getting them working?