Public/Get-TVInfo.ps1
function Get-TVInfo { [CmdletBinding(ConfirmImpact = 'Medium', PositionalBinding = $false, SupportsPaging = $true, SupportsShouldProcess = $true)] param ( [ValidateSet('groups', 'users', 'devices', 'teamviewerpolicies')] [Parameter(Mandatory = $true)] $type, [Parameter(Mandatory = $false)] $filter ) $Method = "GET" if ($filter) { $Uri = "https://webapi.teamviewer.com/api/v1/$type/$filter" } else { $Uri = "https://webapi.teamviewer.com/api/v1/$type" } Write-Host "[$Method] RestMethod: [$Uri]" -ForegroundColor Yellow Try { $Result = Invoke-RestMethod -Method $Method -Uri $Uri -Headers $header -ContentType $ContentType -Verbose -ErrorVariable TVError -ErrorAction SilentlyContinue Return $Result } 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 } } |