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")
}