I'm looking to use a PowerShell script, to assign the 'Inherit' from group setting for policies across all our systems. We have 9,500 workstations, spread between 20 groups, so doing it manually takes forever!
I'm using the below code, in a PowerShell script (teamviewer.ps1) and I have generated an API token. However, it seems to run, only takes about 10 seconds, but nothing happens. No changes appear in the management console, and some systems still show as having no policy applied.


$token = Read-Host -Prompt "Paste your account token code here"
$bearer = "Bearer",$token
$header = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$header.Add("authorization", $bearer)
$request = Invoke-RestMethod -Uri "https://webapi.teamviewer.com/api/v1/devices" -Method Get -Headers $header
$x=1
ForEach($item in $request.devices)
{
$asg = $item.assigned_to
$dev = $item.device_id
If($asg -eq "False")
{
$body = (@{
policy_id = 'inherit'
}) | ConvertTo-Json
Invoke-RestMethod -Uri "https://webapi.teamviewer.com/api/v1/devices/$dev" -Method Put -Headers $header -ContentType application/json -Body $body
$x +=1
}
}
Write-Host "The following devices were not applied the policy change, reason - Not assigned to this account"
$response = Invoke-RestMethod -Uri "https://webapi.teamviewer.com/api/v1/devices" -Method Get -Headers $header
$i=1
Foreach($it in $response.devices)
{
$agn = $it.assigned_to
If(!$agn -eq "False")
{
Write-Host $i ")", $it.alias
$i +=1
}
}