link icon
Ask The Community

TeamViewer is one of the winners of the European Customer Centricity Award 🥳

Please find more information here.

PowerShell Script to Assign Policy to All Systems

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 "" -Method Get -Headers $header
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 "$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 "" -Method Get -Headers $header
Foreach($it in $response.devices)
$agn = $it.assigned_to
If(!$agn -eq "False")
Write-Host $i ")", $it.alias
$i +=1



  • Teja
    Teja Posts: 1

    Hi Digon,

    Did you ever get this to work?



  • Helllo there, 

    i guess here you've used Powershell false.

    If ($asg -eq "False") .. should be If ( $asg -eq $false )


  • techaanderson
    techaanderson Posts: 1


    Were you able to get this working? I continually have issues with devices not inheriting policies from the group when installed.