Would you like to co-innovate with us? If so, we’d like to invite you to become product development partners with us. Read more about it in our announcement Launch of the TeamViewer User Focus Program

Posted by bjblackmore

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


2 Replies
Posted by Teja

Re: PowerShell Script to Assign Policy to All Systems

Hi Digon,

Did you ever get this to work?



Posted by BenSCH

Re: PowerShell Script to Assign Policy to All Systems

Helllo there, 

i guess here you've used Powershell false.

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