Posted by RCT_IT

Unshare and Share groups using TeamViewer API + Powershell

Hi there,

I'm trying to work out this powershell module wrapper that's used for TeamViewer API and can't seem to get my head around it?

I get stuck on this section here:

Unshares a group from certain users.

Unshares a group from certain users.

Teamviewer Group ID

Teamviewer User ID

Is the User Level Token that you can create from the Teamviewer Management Console
Can use Set-TVToken Function will then not be nessessary to use this paramameter

PS C:\> Unshare-TVGroup -GroupID $value1 -UserID $value2

For more Details see Teamviewer API token Documentation
function Unshare-TVGroup
[CmdletBinding(ConfirmImpact = 'Medium',
PositionalBinding = $false,
SupportsPaging = $true,
SupportsShouldProcess = $true)]
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]

if ($token)
{ }
elseif ($global:TVToken)
$token = $global:TVToken
Write-Output "You need to Set the Token"
$header = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$header.Add("authorization", "Bearer $token")
$body = @{
Users = @(
userid = "$UserId"
} | ConvertTo-Json
Invoke-RestMethod -Uri "$groupID/unshare_group" -Method Post -Headers $header -ContentType application/json -Body "$body"

This is apart of the Powershell script located here online:

Error I am getting is:

Invoke-RestMethod : :"Unexpected character encountered while parsing value: {. Path 'Users', line 3, position 19. After parsing a value an unexpected
character was encountered: :. Path 'Users[0]', line 4, position 30. After parsing a value an unexpected character was encountered: :. Path 'Users[0]', line 4, position 30.","error_code":1}
At C:\_RCT\IT TOOLS\Scripts\PowerShell Scripts\TeamViewerPSModules.psm1:701 char:5

Can someone please explain and help me get around this? I am looking to unshare groups with TVUsers and then to Reshare with the same TVUsers, the reason for this is to fix the "Grant Easy Access" which relates back to my replys on this post here:

Our IT accounts are broken without easy access and we are having to refer to alternatives, unattended password, windows credentials, TV ID and password, etc. and everytime we move machines to different groups this feature breaks... hence why I am looking for an easy way to reshare the groups through powershell to speed up the process, and yes TV are aware of the bug as I've mentioned countless times along with the black screen still not working on remote screens?