Hi
I am looking to create a MS Power Automate flow to remove old devices is it possible do via TV API calls ?
Hi,
Yes it is possible.
Here is Poweshell script that you can invoke with Power Automate or any other scheduling tool :)
Sorry about the formatting. Dont know if this forum has code support posts.
$text = "YOUR TV API Key"
$bearer = "Bearer",$text
$header = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$header.Add("authorization", $bearer)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$devices = (Invoke-RestMethod -Uri "Https://webapi.teamviewer.com/api/v1/devices" -Method Get -Headers $header).devices
# $daysAftert to disable is a variable set to from todays date and 90 days backwards. You can change it do desired value.
$daysAfterToDisable = ((Get-Date).AddDays(-90)).GetDateTimeFormats()[48]
foreach ($device in $devices)
{
if ($device.online_state -eq "Offline")
$ID = $device.device_id
$Lastseen = $device.last_seen
if ($null -ne $Lastseen)
$LastSeen = ($device.last_seen).Split("T")[0]
[datetime]$DateLastSeen = $LastSeen
if ($DateLastSeen -le $daysAfterToDisable)
Invoke-WebRequest -Uri "Https://webapi.teamviewer.com/api/v1/devices/$ID" -Method Delete -Headers $header | Out-Null
$message = "Deleted device: $($device.alias)"
Write-Host $message
}
$Lastseen = $null
Join us at FastForward on Oct 14 and make this the last time you fix it.
Learn more about the latest feature we’ve released.
Discover quick, practical tips to get more out of TeamViewer each month.