Public/Set-TVGroupAssignement.ps1

function Set-TVGroupAssignement {
    [CmdletBinding(ConfirmImpact = 'Medium',
        PositionalBinding = $false,
        SupportsPaging = $true,
        SupportsShouldProcess = $true)]
    param
    (
        [Parameter(Mandatory = $true)]
        $DeviceID,
        [Parameter(Mandatory = $true)]
        $GroupID
    )

    $Method = "PUT"

    $Uri = "https://webapi.teamviewer.com/api/v1/devices/$deviceID"

    Write-Host "[$Method] RestMethod: [$Uri]" -ForegroundColor Yellow

    $body = (@{
            groupid = $groupID
        }) | ConvertTo-Json

    if ($PSCmdlet.ShouldProcess("$deviceID" , "Set-TVGroupAssignement")) {
        Try {
            Invoke-RestMethod -Uri $Uri -Method $Method -Headers $header -ContentType $ContentType -Body "$body" -Verbose -ErrorVariable TVError -ErrorAction SilentlyContinue
        } Catch {
            $JsonError = $TVError.Message | ConvertFrom-Json
            $HttpResponse = $TVError.ErrorRecord.Exception.Response
            Write-Host "Error: $($JsonError.error) `nDescription: $($JsonError.error_description) `nErrorCode: $($JsonError.error_code) `nHttp Status Code: $($HttpResponse.StatusCode.value__) `nHttp Description: $($HttpResponse.StatusDescription)" -ForegroundColor Red
        }
    }
}