Creating Groups using a script

I need to create about 3000 groups for the retail division in the management console. Is there a script that I can use to import these groups from a csv file?

Best Answer

Answers

  • W_deFazio
    W_deFazio Posts: 22 Staff member 🤠

    Hello HeinM ,

    Thank you for your post.

    That is possible with the API, for the available API calls please see https://integrate.teamviewer.com/en/develop/api/documentation/ .

    Do you need to just create groups, or also add contacts/machines to these groups all from the CSV file?

    W_deFazio

  • HeinM
    HeinM Posts: 9 ✭✭

    I already have the users on the system and am importing them in bulk using a csv file. But now I have been asked to create a group per store and populate the groups with the machines. All the devices have a unique id that I can use, ie 002701, Group name = "002701 - Brackenfell" and pc name is ad002701e001. The ideal would be to be able to create subgroups, but that is still a dream.

  • W_deFazio
    W_deFazio Posts: 22 Staff member 🤠

    Hello HeinM,

    If I understood correctly, you already have the devices on the contacts list, and you just need to create groups now so you can later move the devices to the designated groups.

    I created a simple Powershell script that will create the groups for you by importing the names of the groups from a .csv file.

    The default of the script is looking for a file named "import.txt" in the C: drive of the machine where you run the script from. But if you want to name the file something else, and have it call it from a different location, just edit the line ($data = Import-Csv "C:\import.txt") with the name and path of your file.

    You will need to edit the script by replacing the word "UserToken" with the API token created with user account level from the TeamViewer account you want to create the groups in. 

    To create the API token with User level, please do the following:

    - Sign in with your TeamViewer account on the Management Console(www.login.teamviewer.com)
    - On the top right of the page click on the blue button with the user name and profile picture
    - Click on "Edit profile"
    - Go to "Apps"
    - Then "Create script token"
    - Select the permissions and click Save.

    Code:

    $header = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $header.Add("authorization", 'Bearer UserToken')

    $data = Import-Csv "C:\import.txt"

    $body = $data
    Foreach($item in $body)
    {
    $name = $item.name
    $body = (@{
    name = "$name"
    }) | ConvertTo-Json
    Invoke-RestMethod -Uri "https://webapi.teamviewer.com/api/v1/groups" -Method Post -Headers $header -ContentType application/json -Body $body
    }

    For the import.txt file, it should look like this:

    name
    groupname1
    groupname2
    groupname3
    groupname4

    Hope it helps!

    W_deFazio