0 votes

Thought I would share my recently created command to disable a TeamViewer account. You'll need a premium or corporate subscription, and create an API token for your company account. More info here: https://integrate.teamviewer.com

I had to use the Invoke-Command workaround to be able to use the Invoke-RestMethod command since it seems it's not supported in the Adaxes Powershell.

I'll be adding more like these to remove deprovisioned computers from the teamviewer groups, or maybe even provision a new user account.

$scriptBlock = {
    $token = "1234567-XXXXXXXXXXXXXXXXXXX"
    $tvApiBaseUrl = "https://webapi.teamviewer.com"

    $headers = @{}
    $headers.Add('Authorization', "Bearer " + $token)

    # find user based on e-mail address
    $uri = $tvApiBaseUrl + "/api/v1/users?email=%mail%"
    $response = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get 

    If ($response.users.Count -gt 0) {
        $userID = $response.users.Get(0).id

        # get all users details
        $uri = $tvApiBaseUrl + "/api/v1/users/" + $userID
        $response = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get 

        # disable user if he is enabled
        If ($response.active -eq $true) {

            $parm = @{}
            $parm.Add("active", $false)
            $body = ConvertTo-Json -InputObject $parm

            $response = Invoke-RestMethod -Uri $uri -Headers $headers -Body $body -Method Put -ContentType "application/json; charset=utf-8"

            #check if user really is deactivated
            $response = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get 
            If ($response.active -eq $False) {
              Return "Teamviewer account has been disabled."
            }
        }
        Else {

            Return "Teamviewer account found, but already inactive."
        }

    }
    Else {
        return "No teamviewer account found for %mail%, de-activation not needed."
    }

}

$result = Invoke-Command -ComputerName localhost -ScriptBlock $scriptBlock

if ($result -ne $NULL)
{
    $Context.LogMessage($result, "Information")
}
by (110 points)

1 Answer

0 votes
by (110 points)

For anyone interested, here's the script to delete all TeamViewer devices that match a Computer Name. For safety I check on minimum computername lenght because you could accidentally remove a lot of devices with this command. So please modify this to your own needs before using.

You'll need to create an API token for your user account in stead of the company account for this one.

$scriptBlock = {
    $token = "1234567-XXXXXXXXXXXXXXXXXXXX"
    $tvApiBaseUrl = "https://webapi.teamviewer.com"

    $hostname = "%cn%"

    # check if hostname string lenght is minimum 7 to prevent accidental deletion
    If ($hostname.Length -lt 7) {
        Throw "ERROR: Hostname lenght to short"
    }

    $headers = @{}
    $headers.Add('Authorization', "Bearer " + $token)

    # get all devices
    $uri = $tvApiBaseUrl + "/api/v1/devices"
    $response = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get 

    $devicesDeleted = 0
    $devicesFailed = 0

    ForEach ($device in $response.devices) {
        If ($device.alias.Length -ge $hostname.Length -And
            $device.alias.Substring(0, $hostname.Length) -eq $hostname) {

            $uri = $tvApiBaseUrl + "/api/v1/devices/" + $device.device_id

            Try 
            {
              $response = Invoke-RestMethod -Uri $uri -Headers $headers -Method Delete
              $devicesDeleted++
             } Catch {
              $devicesFailed++
             }

        }
    }

    Return "Deleted devices: " + $devicesDeleted.ToString() + ", Failed: " + $devicesFailed.ToString()

}

$result = Invoke-Command -ComputerName localhost -ScriptBlock $scriptBlock

if ($result -ne $NULL)
{
    $Context.LogMessage($result, "Information")
}
0

Hello,

Thank you for sharing, much appreciated ;)

0

This is awesome. Do you by chance also have one for provisioning a user in TeamViewer?

Related questions

0 votes
1 answer

Using the built in 'Deprovision' Custom Command, I would like the person that is trying to Deprovision a user (Help Desk member) be asked who (from a list of existing active ... to leave the question 'blank', which means that no one gets access to the mailbox.

asked Apr 22, 2020 by RayBilyk (230 points)
0 votes
1 answer

When we deprovision a user the member of groups are deleted and the power shell scrips only runs as removing all memberships. I can't see what was removed. Is there a scrips I can run prior to removing those memberships that will e-mail what they are?

asked Oct 15, 2019 by meyerm (50 points)
0 votes
1 answer

Hello All, is is possible via Adaxes deprovisioning to remove all his Azure and M365 roles besides custom Powershell script? Regards Ivaylo

asked Mar 31, 2023 by ivaylo.valkov (100 points)
0 votes
1 answer

I have Deprovision set to the following It half works. It will only disable the users and thats it. It wont move them to a disabled users OU, reset the PW or change the ... are empty". I don't know what is wrong or why it isnt working as intended.

asked Nov 28, 2022 by LEGIT1 (150 points)
0 votes
1 answer

I would like the HR to be able to set the date of deprovision User. So that it's executed on set date and not on command. I Tryed with parameter (Date/Time picker) ... it possible with custom command or do i have to make Scheduled Task with (Date/time picker)?

asked Jan 20, 2021 by Sandberg94 (340 points)
3,347 questions
3,048 answers
7,788 comments
545,040 users