PowerShell Script request:
<#
.SYNOPSIS
Set Teamviewer Token for All Other Functions, Also Test the connection to Teamviewer API
.DESCRIPTION
Use to Set Teamviewer Token For All Other Functions.
Will Also use the GET /api/v1/ping API Function
.PARAMETER UserToken
Is the User Level Token that you can create from the Teamviewer Management Console
Use Script and Not App Token and User not Company Token.
.EXAMPLE
PS C:\> Set-TVToken -UserToken $value1
.NOTES
For more Details see Teamviewer API token Documentation
https://www.teamviewer.com/en/for-developers/teamviewer-api/
https://dl.tvcdn.de/integrate/TeamViewer_API_Documentation.pdf
#>
function Set-TVToken
{
[CmdletBinding(ConfirmImpact = 'Medium',
PositionalBinding = $false,
SupportsPaging = $true,
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true)]
[Alias('Token')]
[string]$UserToken
)
$header = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$header.Add("authorization", "Bearer $UserToken")
$TokenTest = Invoke-RestMethod -Uri "https://webapi.teamviewer.com/api/v1/ping" -Method GET -Headers $header -ContentType application/json
if ($TokenTest.token_valid -eq $true)
{
Write-Output "Teamviewer Token Is Working and Set"
$global:TVToken = $UserToken
}
else
{
Write-Output "Teamviewer Token not working"
}
}
.SYNOPSIS
Gets All Teamviewer Device Info from Alias Can be Portion of the alias
.DESCRIPTION
Get all possible information of a Device from it's alias
.PARAMETER alias
Is the Name of the Device seen in all console
.PARAMETER token
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
.EXAMPLE
PS C:\> Get-TVDeviceInfoFromAlias -alias $value1
.NOTES
For more Details see Teamviewer API token Documentation
https://www.teamviewer.com/en/for-developers/teamviewer-api/
https://dl.tvcdn.de/integrate/TeamViewer_API_Documentation.pdf
#>
function Get-TVDeviceInfoFromAlias
{
[CmdletBinding(ConfirmImpact = 'Medium',
PositionalBinding = $false,
SupportsPaging = $true,
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true)]
$alias,
$token
)
if($token)
{}
elseif ($global:TVToken)
{
$token = $global:TVToken
}
else
{
Write-Output "You need to Set the Token"
break
}
$header = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$header.Add("authorization", "Bearer $token")
$Device = Invoke-RestMethod -Uri "https://webapi.teamviewer.com/api/v1/devices?full_list=true" -Method GET -Headers $header -ContentType application/json
$DeviceInformation = $Device.devices | Where-Object { $_.alias -like "*$alias*" }
$DeviceInformation
}
Answer :
remotecontrol_id : r359023409
device_id : d895162687
alias : fts
groupid : g113852238
online_state : Online
assigned_to : False
supported_features : remote_control, chat
How can I describe the answer in this .ps1 request?
#region: XML Output
Write-Verbose "XML Output..."
...
Add comment