├── .gitignore ├── Cmdlets ├── Private │ ├── Get-TeamViewerServiceName.ps1 │ ├── Get-OperatingSystem.ps1 │ ├── Invoke-ExternalCommand.ps1 │ ├── ConvertTo-DateTime.ps1 │ ├── Get-TeamViewerRegKeyPath.ps1 │ ├── Get-ClientId.ps1 │ ├── ConvertTo-TeamViewerRoleAssignedUser.ps1 │ ├── ConvertTo-TeamViewerRoleAssignedUserGroup.ps1 │ ├── ConvertTo-TeamViewerUserGroupAssignedRole.ps1 │ ├── ConvertTo-TeamViewerUserGroup.ps1 │ ├── Get-IpConfig.ps1 │ ├── Get-MSInfo32.ps1 │ ├── ConvertTo-TeamViewerUserGroupMember.ps1 │ ├── Test-TeamViewer32on64.ps1 │ ├── Get-HostFile.ps1 │ ├── Get-TeamViewerApiUri.ps1 │ ├── Resolve-TeamViewerUserEmail.ps1 │ ├── Resolve-TeamViewerRoleId.ps1 │ ├── ConvertTo-TeamViewerManagedGroup.ps1 │ ├── ConvertTo-TeamViewerSsoDomain.ps1 │ ├── Get-TSCSearchDirectory.ps1 │ ├── Resolve-TeamViewerManagerId.ps1 │ ├── Resolve-TeamViewerSsoDomainId.ps1 │ ├── ConvertTo-TeamViewerGroupShare.ps1 │ ├── Resolve-TeamViewerUserId.ps1 │ ├── ConvertTo-TeamViewerPredefinedRole.ps1 │ ├── Resolve-TeamViewerGroupId.ps1 │ ├── Resolve-TeamViewerDeviceId.ps1 │ ├── Resolve-TeamViewerManagedGroupId.ps1 │ ├── Resolve-TeamViewerContactId.ps1 │ ├── Resolve-TeamViewerManagedDeviceId.ps1 │ ├── Resolve-TeamViewerUserGroupId.ps1 │ ├── Get-RouteTable.ps1 │ ├── ConvertTo-TeamViewerPolicy.ps1 │ ├── ConvertTo-TeamViewerGroup.ps1 │ ├── Resolve-TeamViewerUserGroupMemberId.ps1 │ ├── ConvertTo-TeamViewerRole.ps1 │ ├── ConvertTo-TeamViewerManagedDevice.ps1 │ ├── ConvertTo-TeamViewerAuditEvent.ps1 │ ├── ConvertTo-TeamViewerRestError.ps1 │ ├── Resolve-TeamViewerLanguage.ps1 │ ├── ConvertTo-TeamViewerContact.ps1 │ ├── Resolve-TeamViewerPolicyId.ps1 │ ├── ConvertTo-TeamViewerAccount.ps1 │ ├── Test-TcpConnection.ps1 │ ├── Get-TypeAndValueOfRegistryValue.ps1 │ ├── ConvertTo-TeamViewerConnectionReport.ps1 │ ├── Resolve-CustomizationErrorCode.ps1 │ ├── ConvertTo-TeamViewerManager.ps1 │ ├── Resolve-AssignmentErrorCode.ps1 │ ├── ConvertTo-TeamViewerDevice.ps1 │ ├── Get-TeamViewerLinuxGlobalConfig.ps1 │ ├── Add-Registry.ps1 │ ├── Get-InstalledSoftware.ps1 │ └── Get-TSCDirectoryFile.ps1 ├── Public │ ├── Disconnect-TeamViewerApi.ps1 │ ├── Test-TeamViewerInstallation.ps1 │ ├── Connect-TeamViewerApi.ps1 │ ├── Get-TeamViewerService.ps1 │ ├── Get-TeamViewerVersion.ps1 │ ├── Get-TeamViewerId.ps1 │ ├── Invoke-TeamViewerPing.ps1 │ ├── Get-TeamViewerAccount.ps1 │ ├── Stop-TeamViewerService.ps1 │ ├── Start-TeamViewerService.ps1 │ ├── Restart-TeamViewerService.ps1 │ ├── Remove-TeamViewerPSProxy.ps1 │ ├── Set-TeamViewerPSProxy.ps1 │ ├── Get-TeamViewerPredefinedRole.ps1 │ ├── Get-TeamViewerCompanyManagedDevice.ps1 │ ├── Get-TeamViewerEffectivePermission.ps1 │ ├── Get-TeamViewerCustomModuleId.ps1 │ ├── Set-TeamViewerAPIUri.ps1 │ ├── Remove-TeamViewerPredefinedRole.ps1 │ ├── Get-TeamViewerInstallationDirectory.ps1 │ ├── Remove-TeamViewerGroup.ps1 │ ├── Get-TeamViewerSsoExclusion.ps1 │ ├── Get-TeamViewerSsoInclusion.ps1 │ ├── Remove-TeamViewerRole.ps1 │ ├── Remove-TeamViewerUserTFA.ps1 │ ├── Get-TeamViewerSsoDomain.ps1 │ ├── New-TeamViewerManagedGroup.ps1 │ ├── Get-TeamViewerPolicy.ps1 │ ├── Get-TeamViewerManagementId.ps1 │ ├── Remove-TeamViewerPolicy.ps1 │ ├── Remove-TeamViewerManagedGroup.ps1 │ ├── Remove-TeamViewerDevice.ps1 │ ├── Remove-TeamViewerContact.ps1 │ ├── Remove-TeamViewerCustomization.ps1 │ ├── Set-TeamViewerPredefinedRole.ps1 │ ├── Remove-TeamViewerUserGroup.ps1 │ ├── Get-TeamViewerRole.ps1 │ ├── Remove-TeamViewerManagedDeviceManagement.ps1 │ ├── Get-TeamViewerUserByRole.ps1 │ ├── New-TeamViewerUserGroup.ps1 │ ├── Remove-TeamViewerAssignment.ps1 │ ├── Remove-TeamViewerUser.ps1 │ ├── Get-TeamViewerUserGroupByRole.ps1 │ ├── Get-TeamViewerUserGroupMember.ps1 │ ├── New-TeamViewerGroup.ps1 │ ├── Unpublish-TeamViewerGroup.ps1 │ ├── New-TeamViewerPolicy.ps1 │ ├── Remove-TeamViewerManagedDevice.ps1 │ ├── Remove-TeamViewerUserGroupFromRole.ps1 │ ├── Get-TeamViewerRoleByUserGroup.ps1 │ ├── Get-TeamViewerRoleByUser.ps1 │ ├── Add-TeamViewerManagedDevice.ps1 │ ├── Set-TeamViewerUserGroup.ps1 │ ├── Remove-TeamViewerPolicyFromManagedGroup.ps1 │ ├── Get-TeamViewerLogFilePath.ps1 │ ├── New-TeamViewerContact.ps1 │ ├── New-TeamViewerRole.ps1 │ ├── Remove-TeamViewerPolicyFromManagedDevice.ps1 │ ├── Get-TeamViewerUserGroup.ps1 │ ├── Add-TeamViewerUserGroupToRole.ps1 │ ├── Add-TeamViewerCustomization.ps1 │ ├── Set-TeamViewerRole.ps1 │ ├── Publish-TeamViewerGroup.ps1 │ ├── Export-TeamViewerSystemInformation.ps1 │ ├── Get-TeamViewerManager.ps1 │ ├── Add-TeamViewerSsoInclusion.ps1 │ ├── Move-TeamViewerManagedDevice.ps1 │ ├── Get-TeamViewerGroup.ps1 │ ├── Add-TeamViewerAssignment.ps1 │ ├── Add-TeamViewerSsoExclusion.ps1 │ └── Remove-TeamViewerSsoExclusion.ps1 ├── TeamViewerPS.Types.ps1 └── TeamViewerPS.psm1 ├── Linters └── PSScriptAnalyzer.psd1 ├── .vscode ├── spelling ├── extensions.json ├── launch.json └── tasks.json ├── .editorconfig ├── Tests ├── Public │ ├── Set-TeamViewerAPIUri.Tests.ps1 │ ├── Invoke-TeamViewerPackageDownload.Tests.ps1 │ ├── Disconnect-TeamViewerApi.Tests.ps1 │ ├── Remove-TeamViewerPredefinedRole.Tests.ps1 │ ├── Set-TeamViewerPredefinedRole.Tests.ps1 │ ├── Test-TeamViewerInstallation.Tests.ps1 │ ├── Remove-TeamViewerPSProxy.Tests.ps1 │ ├── Connect-TeamViewerApi.Tests.ps1 │ ├── New-TeamViewerGroup.Tests.ps1 │ ├── Invoke-TeamViewerPing.Tests.ps1 │ ├── Get-TeamViewerRoleByUserGroup.Tests.ps1 │ ├── Add-TeamViewerUserGroupToRole.Tests.ps1 │ ├── New-TeamViewerPolicy.Tests.ps1 │ ├── Get-TeamViewerAccount.Tests.ps1 │ ├── Get-TeamViewerLogFilePath.Tests.ps1 │ ├── Get-TeamViewerUserByRole.Tests.ps1 │ ├── Get-TeamViewerUserGroupByRole.Tests.ps1 │ ├── Remove-TeamViewerRole.Tests.ps1 │ ├── Remove-TeamViewerUserGroup.Tests.ps1 │ ├── Remove-TeamViewerUserGroupFromRole.Tests.ps1 │ ├── Remove-TeamViewerDevice.Tests.ps1 │ ├── Remove-TeamViewerContact.Tests.ps1 │ ├── Get-TeamViewerCustomModuleId.Tests.ps1 │ ├── Get-TeamViewerPredefinedRole.Tests.ps1 │ └── New-TeamViewerManagedGroup.Tests.ps1 └── Private │ ├── Test-PowershellFilesValidity.Tests.ps1 │ ├── Test-PrivateFunctions.Tests.ps1 │ ├── Test-PublicFunctions.Tests.ps1 │ └── Test-ManifestFile.Tests.ps1 ├── .github ├── ISSUE_TEMPLATE │ ├── question.md │ ├── feature-request.md │ └── bug-report.md └── workflows │ └── publish_production.yml ├── Docs └── Help │ ├── Remove-TeamViewerPSProxy.md │ ├── Remove-TeamViewerAssignment.md │ ├── Get-TeamViewerCustomModuleId.md │ ├── Get-TeamViewerInstallationDirectory.md │ ├── Remove-TeamViewerCustomization.md │ ├── Get-TeamViewerVersion.md │ ├── Test-TeamViewerInstallation.md │ ├── Get-TeamViewerId.md │ ├── Get-TeamViewerManagementId.md │ ├── Disconnect-TeamViewerApi.md │ ├── Get-TeamViewerLogFilePath.md │ ├── Set-TeamViewerPSProxy.md │ ├── Get-TeamViewerService.md │ ├── Invoke-TeamViewerPing.md │ ├── Get-TeamViewerAccount.md │ ├── Get-TeamViewerEffectivePermission.md │ ├── Set-TeamViewerAPIUri.md │ ├── Remove-TeamViewerPredefinedRole.md │ ├── Get-TeamViewerSsoDomain.md │ ├── Connect-TeamViewerApi.md │ ├── Restart-TeamViewerService.md │ ├── Stop-TeamViewerService.md │ ├── Export-TeamViewerSystemInformation.md │ └── Start-TeamViewerService.md └── LICENSE.md /.gitignore: -------------------------------------------------------------------------------- 1 | /Build/TeamViewerPS 2 | -------------------------------------------------------------------------------- /Cmdlets/Private/Get-TeamViewerServiceName.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerServiceName { 2 | Write-Output 'TeamViewer' 3 | } 4 | -------------------------------------------------------------------------------- /Cmdlets/Public/Disconnect-TeamViewerApi.ps1: -------------------------------------------------------------------------------- 1 | function Disconnect-TeamViewerApi { 2 | $global:PSDefaultParameterValues.Remove("*-Teamviewer*:ApiToken") 3 | } -------------------------------------------------------------------------------- /Linters/PSScriptAnalyzer.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | Severity = @('Error', 'Warning') 3 | ExcludeRules = @('PSUseToExportFieldsInManifest','PSAvoidGlobalVars') 4 | } 5 | -------------------------------------------------------------------------------- /.vscode/spelling: -------------------------------------------------------------------------------- 1 | // Project 2 | TeamViewer 3 | TeamViewer's 4 | TeamViewerPS 5 | 6 | // Powershell 7 | cmdlet 8 | cmdlets 9 | hashtable 10 | Passthru 11 | posh 12 | pwsh 13 | recurse 14 | -------------------------------------------------------------------------------- /Cmdlets/Public/Test-TeamViewerInstallation.ps1: -------------------------------------------------------------------------------- 1 | function Test-TeamViewerInstallation { 2 | if (Get-TeamViewerInstallationDirectory) { 3 | return $true 4 | } 5 | else { 6 | return $false 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = crlf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /Tests/Public/Set-TeamViewerAPIUri.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Set-TeamViewerApiUri.ps1" 3 | 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 5 | ForEach-Object { . $_.FullName } 6 | } 7 | -------------------------------------------------------------------------------- /Tests/Public/Invoke-TeamViewerPackageDownload.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Invoke-TeamViewerPakcageDownload.ps1" 3 | 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 5 | ForEach-Object { . $_.FullName } 6 | } 7 | -------------------------------------------------------------------------------- /Cmdlets/TeamViewerPS.Types.ps1: -------------------------------------------------------------------------------- 1 | enum TeamViewerConnectionReportSessionType { 2 | RemoteConnection = 1 3 | RemoteSupportActive = 2 4 | RemoteSupportActiveSdk = 3 5 | } 6 | 7 | enum PolicyType { 8 | TeamViewer = 1 9 | Monitoring = 4 10 | PatchManagement = 5 11 | } 12 | -------------------------------------------------------------------------------- /Cmdlets/Private/Get-OperatingSystem.ps1: -------------------------------------------------------------------------------- 1 | function Get-OperatingSystem { 2 | if ($IsLinux) { 3 | return 'Linux' 4 | } 5 | if ($IsMacOS) { 6 | return 'MacOS' 7 | } 8 | if ($IsWindows -Or $env:OS -match '^Windows') { 9 | return 'Windows' 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 for the documentation about the extensions.json format 3 | "recommendations": [ 4 | "ms-vscode.PowerShell", 5 | "DavidAnson.vscode-markdownlint", 6 | "streetsidesoftware.code-spell-checker" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /Cmdlets/Public/Connect-TeamViewerApi.ps1: -------------------------------------------------------------------------------- 1 | function Connect-TeamViewerApi { 2 | param( 3 | [Parameter(Mandatory = $true)] 4 | [securestring] 5 | $ApiToken 6 | ) 7 | 8 | if (Invoke-TeamViewerPing -ApiToken $ApiToken) { 9 | $global:PSDefaultParameterValues["*-Teamviewer*:ApiToken"] = $ApiToken 10 | } 11 | } -------------------------------------------------------------------------------- /Cmdlets/Private/Invoke-ExternalCommand.ps1: -------------------------------------------------------------------------------- 1 | function Invoke-ExternalCommand { 2 | param( 3 | [Parameter(Mandatory = $true, Position = 0)] 4 | [string] 5 | $Command, 6 | 7 | [Parameter(ValueFromRemainingArguments = $true)] 8 | [object[]] 9 | $CommandArgs 10 | ) 11 | & $Command @CommandArgs 12 | } 13 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerService.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerService { 2 | switch (Get-OperatingSystem) { 3 | 'Windows' { 4 | Get-Service -Name (Get-TeamViewerServiceName) 5 | } 6 | 'Linux' { 7 | Invoke-ExternalCommand /opt/teamviewer/tv_bin/script/teamviewer daemon status 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: Raise a question 4 | title: "[Question] " 5 | labels: Question 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Summary** 11 | Describe clearly and concisely what is your question. 12 | 13 | **Attachments** 14 | If applicable, provide files (e.g. configuration, log files, screenshots) to help explain your question. 15 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-DateTime.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-DateTime { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [string] 5 | $InputString 6 | ) 7 | 8 | process { 9 | try { 10 | Write-Output ([DateTime]::Parse($InputString)) 11 | } 12 | catch { 13 | Write-Output $null 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerVersion.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerVersion { 2 | if (Test-TeamViewerInstallation) { 3 | switch (Get-OperatingSystem) { 4 | 'Windows' { 5 | return (Get-ItemPropertyValue -Path (Get-TeamViewerRegKeyPath) -Name 'Version') 6 | } 7 | 'Linux' { 8 | return (Get-TeamViewerLinuxGlobalConfig -Name 'Version') 9 | } 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Cmdlets/Private/Get-TeamViewerRegKeyPath.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerRegKeyPath { 2 | param ( 3 | [Parameter()] 4 | [ValidateSet('WOW6432', 'Auto')] 5 | [string] 6 | $Variant = 'Auto' 7 | ) 8 | if (($Variant -eq 'WOW6432') -Or (Test-TeamViewer32on64)) { 9 | Write-Output 'HKLM:\SOFTWARE\Wow6432Node\TeamViewer' 10 | } 11 | else { 12 | Write-Output 'HKLM:\SOFTWARE\TeamViewer' 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerId.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerId { 2 | if (Test-TeamViewerInstallation) { 3 | switch (Get-OperatingSystem) { 4 | 'Windows' { 5 | Write-Output (Get-ItemPropertyValue -Path (Get-TeamViewerRegKeyPath) -Name 'ClientID') 6 | } 7 | 'Linux' { 8 | Write-Output (Get-TeamViewerLinuxGlobalConfig -Name 'ClientID') 9 | } 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Cmdlets/Private/Get-ClientId.ps1: -------------------------------------------------------------------------------- 1 | function Get-ClientId { 2 | if (Test-Path -Path 'HKLM:\SOFTWARE\Wow6432Node\TeamViewer') { 3 | $mainKey = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\TeamViewer' 4 | $id = [int]$mainKey.ClientID 5 | } 6 | elseif (Test-Path -Path 'HKLM:\Software\TeamViewer') { 7 | $mainKey = Get-ItemProperty -Path 'HKLM:\Software\TeamViewer' 8 | $id = [int]$mainKey.ClientID 9 | } 10 | return $id 11 | } 12 | -------------------------------------------------------------------------------- /Cmdlets/TeamViewerPS.psm1: -------------------------------------------------------------------------------- 1 | $ModuleTypes = @( Get-ChildItem -Path "$PSScriptRoot/TeamViewerPS.Types.ps1" -ErrorAction SilentlyContinue ) 2 | $PublicFunctions = @( Get-ChildItem -Path "$PSScriptRoot/Public/*.ps1" -ErrorAction SilentlyContinue ) 3 | $PrivateFunctions = @( Get-ChildItem -Path "$PSScriptRoot/Private/*.ps1" -ErrorAction SilentlyContinue ) 4 | 5 | @($ModuleTypes + $PublicFunctions + $PrivateFunctions) | ForEach-Object { . $_.FullName } 6 | Export-ModuleMember -Function $PublicFunctions.BaseName -Alias * 7 | -------------------------------------------------------------------------------- /Cmdlets/Public/Invoke-TeamViewerPing.ps1: -------------------------------------------------------------------------------- 1 | function Invoke-TeamViewerPing { 2 | param( 3 | [Parameter(Mandatory = $true)] 4 | [securestring] 5 | $ApiToken 6 | ) 7 | 8 | $resourceUri = "$(Get-TeamViewerApiUri)/ping" 9 | $result = Invoke-TeamViewerRestMethod ` 10 | -ApiToken $ApiToken ` 11 | -Uri $resourceUri ` 12 | -Method Get ` 13 | -WriteErrorTo $PSCmdlet ` 14 | -ErrorAction Stop 15 | Write-Output $result.token_valid 16 | } 17 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerRoleAssignedUser.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerRoleAssignedUser { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | process { 8 | $properties = @{AssignedUsers = ($InputObject.trim('u'))} 9 | $result = New-Object -TypeName PSObject -Property $properties 10 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.RoleAssignedUser') 11 | Write-Output $result 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerRoleAssignedUserGroup.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerRoleAssignedUserGroup { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | process { 8 | $properties = @{AssignedGroups = ($InputObject)} 9 | $result = New-Object -TypeName PSObject -Property $properties 10 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.RoleAssignedUserGroup') 11 | Write-Output $result 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerUserGroupAssignedRole.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerRoleAssignedUserGroup { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | process { 8 | $properties = @{AssignedRole = ($InputObject) } 9 | $result = New-Object -TypeName PSObject -Property $properties 10 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.UserGroupAssignedRole') 11 | Write-Output $result 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerAccount.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerAccount { 2 | param( 3 | [Parameter(Mandatory = $true)] 4 | [securestring] 5 | $ApiToken 6 | ) 7 | 8 | $resourceUri = "$(Get-TeamViewerApiUri)/account" 9 | 10 | $response = Invoke-TeamViewerRestMethod ` 11 | -ApiToken $ApiToken ` 12 | -Uri $resourceUri ` 13 | -Method Get ` 14 | -WriteErrorTo $PSCmdlet ` 15 | -ErrorAction Stop 16 | Write-Output ($response | ConvertTo-TeamViewerAccount) 17 | } 18 | -------------------------------------------------------------------------------- /Cmdlets/Public/Stop-TeamViewerService.ps1: -------------------------------------------------------------------------------- 1 | function Stop-TeamViewerService { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param() 4 | 5 | if ($PSCmdlet.ShouldProcess("TeamViewer service")) { 6 | switch (Get-OperatingSystem) { 7 | 'Windows' { 8 | Stop-Service -Name (Get-TeamViewerServiceName) 9 | } 10 | 'Linux' { 11 | Invoke-ExternalCommand /opt/teamviewer/tv_bin/script/teamviewer daemon stop 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Cmdlets/Public/Start-TeamViewerService.ps1: -------------------------------------------------------------------------------- 1 | function Start-TeamViewerService { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param() 4 | 5 | if ($PSCmdlet.ShouldProcess("TeamViewer service")) { 6 | switch (Get-OperatingSystem) { 7 | 'Windows' { 8 | Start-Service -Name (Get-TeamViewerServiceName) 9 | } 10 | 'Linux' { 11 | Invoke-ExternalCommand /opt/teamviewer/tv_bin/script/teamviewer daemon start 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Cmdlets/Public/Restart-TeamViewerService.ps1: -------------------------------------------------------------------------------- 1 | function Restart-TeamViewerService { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param() 4 | 5 | if ($PSCmdlet.ShouldProcess('TeamViewer service')) { 6 | switch (Get-OperatingSystem) { 7 | 'Windows' { 8 | Restart-Service -Name (Get-TeamViewerServiceName) 9 | } 10 | 'Linux' { 11 | Invoke-ExternalCommand /opt/teamviewer/tv_bin/script/teamviewer daemon restart 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerUserGroup.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerUserGroup { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | process { 8 | $properties = @{ 9 | Id = [UInt64]$InputObject.id 10 | Name = $InputObject.name 11 | } 12 | $result = New-Object -TypeName PSObject -Property $properties 13 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.UserGroup') 14 | Write-Output $result 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Cmdlets/Private/Get-IpConfig.ps1: -------------------------------------------------------------------------------- 1 | function Get-IpConfig { 2 | param( 3 | [Parameter(ValueFromPipeline = $true)] 4 | [string] 5 | $OutputPath 6 | ) 7 | Process { 8 | try { 9 | ipconfig /all | Out-File -FilePath "$OutputPath\Data\ipconfig.txt" -Encoding utf8 10 | Write-Output "ipconfig data collected and saved to $OutputPath\Data\ipconfig.txt" 11 | } 12 | catch { 13 | Write-Error "An error occurred while collecting ipconfig data: $_" 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Cmdlets/Private/Get-MSInfo32.ps1: -------------------------------------------------------------------------------- 1 | function Get-MSInfo32 { 2 | param( 3 | [Parameter(ValueFromPipeline = $true)] 4 | [string] 5 | $OutputPath 6 | ) 7 | Process { 8 | try { 9 | Start-Process -FilePath msinfo32.exe -ArgumentList "/nfo $OutputPath\Data\msinfo32.nfo" -Wait 10 | 11 | Write-Output "msinfo data collected and saved to $OutputPath\Data\msinfo32.nfo" 12 | } 13 | catch { 14 | Write-Error "An error occurred while collecting msinfo data: $_" 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerUserGroupMember.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerUserGroupMember { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | process { 8 | $properties = @{ 9 | AccountId = [int]$InputObject.accountId 10 | Name = $InputObject.name 11 | } 12 | $result = New-Object -TypeName PSObject -Property $properties 13 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.UserGroupMember') 14 | Write-Output $result 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Create a feature request 4 | title: "[Feature] " 5 | labels: Feature 6 | assignees: ChristianJ-TV 7 | 8 | --- 9 | 10 | **Summary** 11 | Describe clearly and concisely of what the problem is. 12 | 13 | **Expected Solution** 14 | Describe the solution you'd like or what you want to happen. 15 | 16 | **Considerations** 17 | Any alternative solutions or ideas you've considered. 18 | 19 | **Attachments** 20 | If applicable, provide files (e.g. configuration, log files, screenshots) to help explain your idea. 21 | -------------------------------------------------------------------------------- /Cmdlets/Private/Test-TeamViewer32on64.ps1: -------------------------------------------------------------------------------- 1 | function Test-TeamViewer32on64 { 2 | if (![Environment]::Is64BitOperatingSystem) { 3 | return $false 4 | } 5 | $registryKey = Get-TeamViewerRegKeyPath -Variant WOW6432 6 | if (!(Test-Path $registryKey)) { 7 | return $false 8 | } 9 | try { 10 | $installationDirectory = (Get-Item $registryKey).GetValue('InstallationDirectory') 11 | $binaryPath = Join-Path $installationDirectory 'TeamViewer.exe' 12 | return Test-Path $binaryPath 13 | } 14 | catch { 15 | return $false 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Create a bug report 4 | title: "[Bug] " 5 | labels: Bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Summary** 11 | Describe clearly and concisely what is not working or is wrong. 12 | 13 | **Expected Behavior** 14 | Describe what you expected to happen. 15 | 16 | **Setps To Reproduce** 17 | Describe the steps to reproduce the behavior: 18 | 1. Configure '...' with value '...' 19 | 2. Execute with "..." 20 | 3. See error ... 21 | 22 | **Attachments** 23 | If applicable, provide files (e.g. configuration, log files, screenshots) to help explain your problem. 24 | -------------------------------------------------------------------------------- /Tests/Public/Disconnect-TeamViewerApi.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Disconnect-TeamViewerApi.ps1" 3 | } 4 | 5 | Describe 'Disconnect-TeamViewerApi' { 6 | BeforeEach { 7 | $global:PSDefaultParameterValues["*-Teamviewer*:ApiToken"] = 'test123' 8 | } 9 | 10 | It 'Should remove the PSDefaultParameterValues for the TeamViewer cmdlets' { 11 | $global:PSDefaultParameterValues["*-Teamviewer*:ApiToken"] | Should -Be 'test123' 12 | Disconnect-TeamViewerApi 13 | $global:PSDefaultParameterValues["*-Teamviewer*:ApiToken"] | Should -BeNullOrEmpty 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Cmdlets/Private/Get-HostFile.ps1: -------------------------------------------------------------------------------- 1 | function Get-HostFile { 2 | param( 3 | [Parameter(ValueFromPipeline = $true)] 4 | [string] 5 | $OutputPath 6 | ) 7 | process { 8 | $regPath = 'HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters' 9 | $regKey = Get-ItemProperty -Path $regPath 10 | $hostsPath = Join-Path -Path $regKey.DataBasePath -ChildPath 'hosts' 11 | $hostsFile = Get-Content -Path $hostsPath 12 | $hostsFile | Out-File -FilePath "$OutputPath\Data\hosts.txt" 13 | Write-Output "hosts file collected and saved to $OutputPath\Data\hosts.txt" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Cmdlets/Private/Get-TeamViewerApiUri.ps1: -------------------------------------------------------------------------------- 1 | 2 | 3 | class TeamViewerConfiguration { 4 | [string]$APIUri = 'https://webapi.teamviewer.com/api/v1' 5 | 6 | static [TeamViewerConfiguration] $Instance = $null 7 | 8 | static [TeamViewerConfiguration] GetInstance() { 9 | if (-not [TeamViewerConfiguration]::Instance) { 10 | [TeamViewerConfiguration]::Instance = [TeamViewerConfiguration]::new() 11 | } 12 | 13 | return [TeamViewerConfiguration]::Instance 14 | } 15 | } 16 | 17 | function Get-TeamViewerAPIUri { 18 | $config = [TeamViewerConfiguration]::GetInstance() 19 | return $config.APIUri 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerPSProxy.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamViewerPSProxy { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param() 4 | 5 | $global:TeamViewerProxyUriRemoved = $true 6 | $global:TeamViewerProxyUriRemoved | Out-Null # https://github.com/PowerShell/PSScriptAnalyzer/issues/1472 7 | if($PSCmdlet.ShouldProcess($TeamViewerProxyUriRemoved,"Remove proxy for WebAPI")){ 8 | $global:TeamViewerProxyUriSet = $null 9 | $global:TeamViewerProxyUriSet | Out-Null # https://github.com/PowerShell/PSScriptAnalyzer/issues/1472 10 | [Environment]::SetEnvironmentVariable('TeamViewerProxyUri','', 'User') 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Cmdlets/Private/Resolve-TeamViewerUserEmail.ps1: -------------------------------------------------------------------------------- 1 | function Resolve-TeamViewerUserEmail { 2 | param( 3 | [Parameter(ValueFromPipeline = $true, Mandatory = $false)] 4 | [object] 5 | $User 6 | ) 7 | Process { 8 | if (!$User) { 9 | return $null 10 | } 11 | elseif ($User.PSObject.TypeNames -contains 'TeamViewerPS.User') { 12 | return $User.Email 13 | } 14 | elseif ($User -is [string]) { 15 | return $User 16 | } 17 | else { 18 | throw "Invalid user email '$User'. Must be either a [TeamViewerPS.User] or [string]." 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Cmdlets/Private/Resolve-TeamViewerRoleId.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Resolve-TeamViewerRoleId { 3 | param( 4 | [Parameter(ValueFromPipeline = $true, Mandatory = $true)] 5 | [Object] 6 | $Role 7 | ) 8 | Process { 9 | if ($Role.PSObject.TypeNames -contains 'TeamViewerPS.Role') { 10 | return [string]$Role.RoleID 11 | } 12 | elseif ($Role -match '^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$') { 13 | return [string]$Role 14 | } 15 | else { 16 | throw "Invalid role identifier '$Role'. Must be either a [TeamViewerPS.Role] or [UUID] " 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerManagedGroup.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerManagedGroup { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | process { 8 | $properties = @{ 9 | Id = [guid]$InputObject.id 10 | Name = $InputObject.name 11 | } 12 | if ($InputObject.policy_id) { 13 | $properties["PolicyId"] = $InputObject.policy_id 14 | } 15 | $result = New-Object -TypeName PSObject -Property $properties 16 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.ManagedGroup') 17 | Write-Output $result 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Cmdlets/Public/Set-TeamViewerPSProxy.ps1: -------------------------------------------------------------------------------- 1 | $global:TeamViewerProxyUriSet = $null 2 | 3 | function Set-TeamViewerPSProxy { 4 | [CmdletBinding(SupportsShouldProcess =$true)] 5 | param ( 6 | [Parameter(Mandatory=$true)] 7 | [Uri] 8 | $ProxyUri 9 | ) 10 | 11 | if($PSCmdlet.ShouldProcess($ProxyUri,"Sets proxy for WebAPI")){ 12 | $global:TeamViewerProxyUriSet = $ProxyUri 13 | $global:TeamViewerProxyUriRemoved = $false 14 | $global:TeamViewerProxyUriRemoved | Out-Null 15 | 16 | [Environment]::SetEnvironmentVariable("TeamViewerProxyUri", $ProxyUri, "User") 17 | 18 | Write-Output "Proxy set to $TeamViewerProxyUriSet" 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerSsoDomain.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerSsoDomain { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | process { 8 | $properties = @{ 9 | Id = $InputObject.DomainId 10 | Name = $InputObject.DomainName 11 | } 12 | $result = New-Object -TypeName PSObject -Property $properties 13 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.SsoDomain') 14 | $result | Add-Member -MemberType ScriptMethod -Name "ToString" -Force -Value { 15 | Write-Output "$($this.Name)" 16 | } 17 | Write-Output $result 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Cmdlets/Private/Get-TSCSearchDirectory.ps1: -------------------------------------------------------------------------------- 1 | function Get-TSCSearchDirectory { 2 | $LocalAppData = [System.Environment]::GetFolderPath('LocalApplicationData') 3 | $RoamingAppData = [System.Environment]::GetFolderPath('ApplicationData') 4 | $TVAppData = Join-Path -Path $LocalAppData.ToString() -ChildPath 'TeamViewer/Logs' 5 | $TVRoamingData = Join-Path -Path $RoamingAppData.ToString() -ChildPath 'TeamViewer' 6 | $InstallationDirectory = Get-TeamViewerInstallationDirectory 7 | 8 | $TSCSearchDirectory = @{ 9 | 'TeamViewer_Version15' = $InstallationDirectory 10 | 'AppData\TeamViewer' = @($TVAppData; $TVRoamingData) 11 | } 12 | 13 | return $TSCSearchDirectory 14 | } 15 | -------------------------------------------------------------------------------- /Cmdlets/Private/Resolve-TeamViewerManagerId.ps1: -------------------------------------------------------------------------------- 1 | function Resolve-TeamViewerManagerId { 2 | param( 3 | [Parameter(ValueFromPipeline = $true, Mandatory = $true)] 4 | [object] 5 | $Manager 6 | ) 7 | Process { 8 | if ($Manager.PSObject.TypeNames -contains 'TeamViewerPS.Manager') { 9 | return [guid]$Manager.Id 10 | } 11 | elseif ($Manager -is [string]) { 12 | return [guid]$Manager 13 | } 14 | elseif ($Manager -is [guid]) { 15 | return $Manager 16 | } 17 | else { 18 | throw "Invalid manager identifier '$Manager'. Must be either a [TeamViewerPS.Manager], [guid] or [string]." 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerPredefinedRole.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerPredefinedRole { 2 | param( 3 | [Parameter(Mandatory = $true)] 4 | [securestring] 5 | $ApiToken 6 | ) 7 | 8 | 9 | Begin { 10 | $parameters = @{} 11 | $resourceUri = "$(Get-TeamViewerApiUri)/userroles/predefined" 12 | } 13 | 14 | Process { 15 | $response = Invoke-TeamViewerRestMethod ` 16 | -ApiToken $ApiToken ` 17 | -Uri $resourceUri ` 18 | -Method Get ` 19 | -Body $parameters ` 20 | -WriteErrorTo $PSCmdlet ` 21 | -ErrorAction Stop 22 | Write-Output ($response | ConvertTo-TeamViewerPredefinedRole) 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Cmdlets/Private/Resolve-TeamViewerSsoDomainId.ps1: -------------------------------------------------------------------------------- 1 | function Resolve-TeamViewerSsoDomainId { 2 | param( 3 | [Parameter(ValueFromPipeline = $true, Mandatory = $true)] 4 | [object] 5 | $Domain 6 | ) 7 | Process { 8 | if ($Domain.PSObject.TypeNames -contains 'TeamViewerPS.SsoDomain') { 9 | return [guid]$Domain.Id 10 | } 11 | elseif ($Domain -is [string]) { 12 | return [guid]$Domain 13 | } 14 | elseif ($Domain -is [guid]) { 15 | return $Domain 16 | } 17 | else { 18 | throw "Invalid SSO domain identifier '$Domain'. Must be either a [TeamViewerPS.SsoDomain], [guid] or [string]." 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerGroupShare.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerGroupShare { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | process { 8 | $properties = @{ 9 | UserId = $InputObject.userid 10 | Name = $InputObject.name 11 | Permissions = $InputObject.permissions 12 | } 13 | $result = New-Object -TypeName PSObject -Property $properties 14 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.GroupShare') 15 | $result | Add-Member -MemberType ScriptMethod -Name "ToString" -Force -Value { 16 | Write-Output "$($this.UserId)" 17 | } 18 | Write-Output $result 19 | } 20 | } -------------------------------------------------------------------------------- /Cmdlets/Private/Resolve-TeamViewerUserId.ps1: -------------------------------------------------------------------------------- 1 | function Resolve-TeamViewerUserId { 2 | param( 3 | [Parameter(ValueFromPipeline = $true, Mandatory = $true)] 4 | [object] 5 | $User 6 | ) 7 | Process { 8 | if ($User.PSObject.TypeNames -contains 'TeamViewerPS.User') { 9 | return $User.Id 10 | } 11 | elseif ($User -is [string]) { 12 | if ($User -notmatch 'u[0-9]+') { 13 | throw "Invalid user identifier '$User'. String must be a user ID in the form 'u123456789'." 14 | } 15 | return $User 16 | } 17 | else { 18 | throw "Invalid user identifier '$User'. Must be either a [TeamViewerPS.User] or [string]." 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerPredefinedRole.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerPredefinedRole { 2 | param( 3 | [Parameter(ValueFromPipeline = $true)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | process { 8 | if ($InputObject) { 9 | $properties = @{ 10 | PredefinedRoleId = $InputObject.PredefinedUserRoleId 11 | } 12 | } 13 | 14 | $result = New-Object -TypeName PSObject -Property $properties 15 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.PredefinedRole') 16 | $result | Add-Member -MemberType ScriptMethod -Name 'ToString' -Force -Value { 17 | Write-Output "[$($this.PredefinedRoleID)]" 18 | } 19 | Write-Output $result 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Cmdlets/Private/Resolve-TeamViewerGroupId.ps1: -------------------------------------------------------------------------------- 1 | function Resolve-TeamViewerGroupId { 2 | param( 3 | [Parameter(ValueFromPipeline = $true, Mandatory = $true)] 4 | [object] 5 | $Group 6 | ) 7 | Process { 8 | if ($Group.PSObject.TypeNames -contains 'TeamViewerPS.Group') { 9 | return $Group.Id 10 | } 11 | elseif ($Group -is [string]) { 12 | if ($Group -notmatch 'g[0-9]+') { 13 | throw "Invalid group identifier '$Group'. String must be a group ID in the form 'g123456789'." 14 | } 15 | return $Group 16 | } 17 | else { 18 | throw "Invalid group identifier '$Group'. Must be either a [TeamViewerPS.Group] or [string]." 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Cmdlets/Private/Resolve-TeamViewerDeviceId.ps1: -------------------------------------------------------------------------------- 1 | function Resolve-TeamViewerDeviceId { 2 | param( 3 | [Parameter(ValueFromPipeline = $true, Mandatory = $true)] 4 | [object] 5 | $Device 6 | ) 7 | Process { 8 | if ($Device.PSObject.TypeNames -contains 'TeamViewerPS.Device') { 9 | return $Device.Id 10 | } 11 | elseif ($Device -is [string]) { 12 | if ($Device -notmatch 'd[0-9]+') { 13 | throw "Invalid device identifier '$Device'. String must be a device ID in the form 'd123456789'." 14 | } 15 | return $Device 16 | } 17 | else { 18 | throw "Invalid device identifier '$Device'. Must be either a [TeamViewerPS.Device] or [string]." 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Cmdlets/Private/Resolve-TeamViewerManagedGroupId.ps1: -------------------------------------------------------------------------------- 1 | function Resolve-TeamViewerManagedGroupId { 2 | param( 3 | [Parameter(ValueFromPipeline = $true, Mandatory = $true)] 4 | [object] 5 | $ManagedGroup 6 | ) 7 | Process { 8 | if ($ManagedGroup.PSObject.TypeNames -contains 'TeamViewerPS.ManagedGroup') { 9 | return [guid]$ManagedGroup.Id 10 | } 11 | elseif ($ManagedGroup -is [string]) { 12 | return [guid]$ManagedGroup 13 | } 14 | elseif ($ManagedGroup -is [guid]) { 15 | return $ManagedGroup 16 | } 17 | else { 18 | throw "Invalid managed group identifier '$ManagedGroup'. Must be either a [TeamViewerPS.ManagedGroup], [guid] or [string]." 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Cmdlets/Private/Resolve-TeamViewerContactId.ps1: -------------------------------------------------------------------------------- 1 | function Resolve-TeamViewerContactId { 2 | param( 3 | [Parameter(ValueFromPipeline = $true, Mandatory = $true)] 4 | [object] 5 | $Contact 6 | ) 7 | Process { 8 | if ($Contact.PSObject.TypeNames -contains 'TeamViewerPS.Contact') { 9 | return $Contact.Id 10 | } 11 | elseif ($Contact -is [string]) { 12 | if ($Contact -notmatch 'c[0-9]+') { 13 | throw "Invalid contact identifier '$Contact'. String must be a contact ID in the form 'c123456789'." 14 | } 15 | return $Contact 16 | } 17 | else { 18 | throw "Invalid contact identifier '$Contact'. Must be either a [TeamViewerPS.Contact] or [string]." 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Cmdlets/Private/Resolve-TeamViewerManagedDeviceId.ps1: -------------------------------------------------------------------------------- 1 | function Resolve-TeamViewerManagedDeviceId { 2 | param( 3 | [Parameter(ValueFromPipeline = $true, Mandatory = $true)] 4 | [object] 5 | $ManagedDevice 6 | ) 7 | Process { 8 | if ($ManagedDevice.PSObject.TypeNames -contains 'TeamViewerPS.ManagedDevice') { 9 | return [guid]$ManagedDevice.Id 10 | } 11 | elseif ($ManagedDevice -is [string]) { 12 | return [guid]$ManagedDevice 13 | } 14 | elseif ($ManagedDevice -is [guid]) { 15 | return $ManagedDevice 16 | } 17 | else { 18 | throw "Invalid managed device identifier '$ManagedDevice'. Must be either a [TeamViewerPS.ManagedDevice], [guid] or [string]." 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerCompanyManagedDevice.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerCompanyManagedDevice { 2 | param( 3 | [Parameter(Mandatory = $true)] 4 | [securestring] 5 | $ApiToken 6 | ) 7 | 8 | $resourceUri = "$(Get-TeamViewerApiUri)/managed/devices/company" 9 | $parameters = @{} 10 | 11 | do { 12 | $response = Invoke-TeamViewerRestMethod ` 13 | -ApiToken $ApiToken ` 14 | -Uri $resourceUri ` 15 | -Method Get ` 16 | -Body $parameters ` 17 | -WriteErrorTo $PSCmdlet ` 18 | -ErrorAction Stop 19 | 20 | $parameters.paginationToken = $response.nextPaginationToken 21 | Write-Output ($response.resources | ConvertTo-TeamViewerManagedDevice) 22 | } while ($parameters.paginationToken) 23 | } 24 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerEffectivePermission.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerEffectivePermission { 2 | [CmdletBinding(DefaultParameterSetName = '')] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken 7 | ) 8 | 9 | begin { 10 | $resourceUri = "$(Get-TeamViewerApiUri)/users/effectivepermissions" 11 | } 12 | 13 | process { 14 | $response = Invoke-TeamViewerRestMethod ` 15 | -ApiToken $ApiToken ` 16 | -Uri $resourceUri ` 17 | -Method Get ` 18 | -WriteErrorTo $PSCmdlet ` 19 | -ErrorAction Stop 20 | if ($null -eq $response -or $response.Count -eq 0) { 21 | $response = @{} 22 | } 23 | return [PSCustomObject] $response 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Cmdlets/Private/Resolve-TeamViewerUserGroupId.ps1: -------------------------------------------------------------------------------- 1 | function Resolve-TeamViewerUserGroupId { 2 | param( 3 | [Parameter(ValueFromPipeline = $true, Mandatory = $true)] 4 | [object] 5 | $UserGroup 6 | ) 7 | Process { 8 | if ($UserGroup.PSObject.TypeNames -contains 'TeamViewerPS.UserGroup') { 9 | return [UInt64]$UserGroup.Id 10 | } 11 | elseif ($UserGroup -is [string]) { 12 | return [UInt64]$UserGroup 13 | } 14 | elseif ($UserGroup -is [UInt64] -or $UserGroup -is [Int64] -or $UserGroup -is [int]) { 15 | return [UInt64]$UserGroup 16 | } 17 | else { 18 | throw "Invalid user group identifier '$UserGroup'. Must be either a [TeamViewerPS.UserGroup], [UInt64], [Int64] or [string]." 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?linkid=830387 for the documentation about the tasks.json format 3 | "version": "0.2.0", 4 | "configurations": [ 5 | { 6 | "name": "Lint (via PSScriptAnalyzer)", 7 | "type": "PowerShell", 8 | "request": "launch", 9 | "script": "Invoke-ScriptAnalyzer -Path '${workspaceFolder}' -Recurse -Settings '${workspaceFolder}/Linters/PSScriptAnalyzer.psd1'", 10 | "createTemporaryIntegratedConsole": true 11 | }, 12 | { 13 | "name": "Test (via Pester)", 14 | "type": "PowerShell", 15 | "request": "launch", 16 | "script": "Invoke-Pester -Path '${workspaceFolder}'", 17 | "createTemporaryIntegratedConsole": true 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerCustomModuleId.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerCustomModuleId { 2 | 3 | if (Test-TeamViewerinstallation) { 4 | $fileName = 'TeamViewer.json' 5 | $installationDirectory = Get-TeamViewerInstallationDirectory 6 | $filePath = Join-Path -Path $installationDirectory -ChildPath $fileName 7 | if (Test-Path -Path $filePath) { 8 | $jsonContent = Get-Content -Path $FilePath -Raw 9 | $jsonObject = ConvertFrom-Json $jsonContent 10 | if ($jsonObject.id) { 11 | return $jsonObject.id 12 | } 13 | } 14 | else { 15 | Write-Error 'Custom module Id cannot be found. Check if customization is applied.' 16 | } 17 | } 18 | else { 19 | Write-Error 'TeamViewer is not installed' 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Cmdlets/Private/Get-RouteTable.ps1: -------------------------------------------------------------------------------- 1 | function Get-RouteTable { 2 | param( 3 | [Parameter(ValueFromPipeline = $true)] 4 | [string] 5 | $OutputPath 6 | ) 7 | Process{ 8 | try { 9 | $processInfo = New-Object System.Diagnostics.ProcessStartInfo 10 | $processInfo.FileName = 'route.exe' 11 | $processInfo.Arguments = 'print' 12 | $processInfo.WindowStyle = 'Hidden' 13 | $processInfo.UseShellExecute = $false 14 | $processInfo.RedirectStandardOutput = $true 15 | 16 | $process = [System.Diagnostics.Process]::Start($processInfo) 17 | $output = $process.StandardOutput.ReadToEnd() 18 | $output | Out-File "$OutputPath\Data\RouteTable.txt" 19 | } 20 | catch { 21 | Write-Error "An error occurred while collecting RouteTable data: $_" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Cmdlets/Public/Set-TeamViewerAPIUri.ps1: -------------------------------------------------------------------------------- 1 | function Set-TeamViewerAPIUri { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param ( 4 | [Parameter(Mandatory = $false)] 5 | [string]$NewUri, 6 | [Parameter(Mandatory = $false)] 7 | [bool]$Default 8 | ) 9 | 10 | $config = [TeamViewerConfiguration]::GetInstance() 11 | $PSDefaultParameterValues = @{'CmdletName:Default' = $true } 12 | 13 | if ($PSCmdlet.ShouldProcess('TeamViewer account')) { 14 | if ($NewUri) { 15 | $config.APIUri = $NewUri 16 | Write-Output "TeamViewer API URL set to: $($config.APIUri)" 17 | } 18 | elseif ($Default) { 19 | $config.APIUri = 'https://webapi.teamviewer.com/api/v1' 20 | Write-Output "TeamViewer API URL set to: $($config.APIUri)" 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerPredefinedRole.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamViewerPredefinedRole { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken 7 | ) 8 | 9 | 10 | Begin { 11 | $parameters = @{} 12 | $resourceUri = "$(Get-TeamViewerApiUri)/userroles/predefined" 13 | } 14 | 15 | Process { 16 | if ($PSCmdlet.ShouldProcess('PredefinedRole', 'Remove Predefined role')) { 17 | Invoke-TeamViewerRestMethod ` 18 | -ApiToken $ApiToken ` 19 | -Uri $resourceUri ` 20 | -Method DELETE ` 21 | -Body $parameters ` 22 | -WriteErrorTo $PSCmdlet ` 23 | -ErrorAction Stop | ` 24 | Out-Null 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerPolicy.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerPolicy { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | 8 | process { 9 | $properties = @{ 10 | Id = $InputObject.policy_id 11 | Name = $InputObject.name 12 | Settings = @( 13 | $InputObject.settings | ForEach-Object { 14 | @{ 15 | Key = $_.key 16 | Value = $_.value 17 | Enforce = $_.enforce 18 | } 19 | } 20 | ) 21 | } 22 | 23 | $result = New-Object -TypeName PSObject -Property $properties 24 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.Policy') 25 | Write-Output $result 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Docs/Help/Remove-TeamViewerPSProxy.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Remove-TeamViewerPSProxy 5 | schema: 2.0.0 6 | --- 7 | 8 | # Remove-TeamViewerPSProxy 9 | 10 | ## SYNOPSIS 11 | 12 | Remove TeamViewerPS proxy. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Remove-TeamViewerPSProxy 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Removes the proxy and sets it to default for TeamViewerPS module functions. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS /> Remove-TeamViewerPSProxy 30 | ``` 31 | 32 | Removes the existing proxy server used and sets it to default. 33 | 34 | ## PARAMETERS 35 | 36 | ### CommonParameters 37 | 38 | ## INPUTS 39 | 40 | ### None 41 | 42 | ## OUTPUTS 43 | 44 | ## NOTES 45 | 46 | ## RELATED LINKS 47 | -------------------------------------------------------------------------------- /Docs/Help/Remove-TeamViewerAssignment.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Remove-TeamViewerAssignment.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Remove-TeamViewerAssignment 9 | 10 | ## SYNOPSIS 11 | 12 | Unassigns the device from its current company. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Remove-TeamViewerAssignment 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Unassigns the calling device from its company. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS /> Remove-TeamViewerAssignment 30 | ``` 31 | 32 | Unassigns the device from its company. 33 | 34 | ## PARAMETERS 35 | 36 | ### CommonParameters 37 | 38 | ### None 39 | 40 | ## INPUTS 41 | 42 | ### None 43 | 44 | ## OUTPUTS 45 | 46 | ## NOTES 47 | 48 | ## RELATED LINKS 49 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerGroup.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerGroup { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | process { 8 | $properties = @{ 9 | Id = $InputObject.id 10 | Name = $InputObject.name 11 | Permissions = $InputObject.permissions 12 | SharedWith = @($InputObject.shared_with | ConvertTo-TeamViewerGroupShare) 13 | } 14 | if ($InputObject.owner) { 15 | $properties.Owner = [pscustomobject]@{ 16 | UserId = $InputObject.owner.userid 17 | Name = $InputObject.owner.name 18 | } 19 | } 20 | $result = New-Object -TypeName PSObject -Property $properties 21 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.Group') 22 | Write-Output $result 23 | } 24 | } -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerInstallationDirectory.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerInstallationDirectory { 2 | switch (Get-OperatingSystem) { 3 | 'Windows' { 4 | $regKey = Get-TeamViewerRegKeyPath 5 | $installationDirectory = if (Test-Path $regKey) { 6 | (Get-Item $regKey).GetValue('InstallationDirectory') 7 | } 8 | if ( 9 | $installationDirectory -And ` 10 | (Test-Path "$installationDirectory/TeamViewer.exe") 11 | ) { 12 | return $installationDirectory 13 | } 14 | } 15 | 'Linux' { 16 | if ( 17 | (Test-Path '/opt/teamviewer/tv_bin/TeamViewer') 18 | ) { 19 | return '/opt/teamviewer/tv_bin/' 20 | } 21 | } 22 | default { 23 | Write-Error 'TeamViewer not installed' 24 | } 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Docs/Help/Get-TeamViewerCustomModuleId.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Get-TeamViewerCustomModuleId.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-TeamViewerCustomModuleId 9 | 10 | ## SYNOPSIS 11 | 12 | Retrieves the currently applied TeamViewer custom module's ID. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Get-TeamViewerCustomModuleId 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | The command checks the TeamViewer Installation and returns the custom module ID. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS /> Get-TeamViewerCustomModuleId 30 | ``` 31 | 32 | Returns the custom module id. 33 | 34 | ## PARAMETERS 35 | 36 | ### CommonParameters 37 | 38 | ### None 39 | 40 | ## INPUTS 41 | 42 | ### None 43 | 44 | ## OUTPUTS 45 | 46 | ## NOTES 47 | 48 | ## RELATED LINKS 49 | -------------------------------------------------------------------------------- /Tests/Public/Remove-TeamViewerPredefinedRole.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Remove-TeamViewerPredefinedRole.ps1" 3 | 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 5 | ForEach-Object { . $_.FullName } 6 | 7 | $testApiToken = [securestring]@{} 8 | $null = $testApiToken 9 | 10 | Mock Get-TeamViewerApiUri { '//unit.test' } 11 | Mock Invoke-TeamViewerRestMethod 12 | } 13 | 14 | 15 | Describe 'Remove-TeamViewerPredefinedRole' { 16 | It 'Should call the correct API endpoint to remove PredefinedRole' { 17 | Remove-TeamViewerPredefinedRole -ApiToken $testApiToken 18 | 19 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 20 | $ApiToken -eq $testApiToken -And ` 21 | $Uri -eq "//unit.test/userroles/predefined" -And ` 22 | $Method -eq 'Delete' } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Cmdlets/Private/Resolve-TeamViewerUserGroupMemberId.ps1: -------------------------------------------------------------------------------- 1 | function Resolve-TeamViewerUserGroupMemberMemberId { 2 | param( 3 | [Parameter(ValueFromPipeline = $true, Mandatory = $true)] 4 | [object] 5 | $UserGroupMember 6 | ) 7 | Process { 8 | if ($UserGroupMember.PSObject.TypeNames -contains 'TeamViewerPS.UserGroupMember') { 9 | return $UserGroupMember.AccountId 10 | } 11 | elseif ($UserGroupMember -match 'u[0-9]+') { 12 | return $UserGroupMember 13 | } 14 | elseif ($UserGroupMember -is [string]) { 15 | return [int]$UserGroupMember 16 | } 17 | elseif ($UserGroupMember -is [int]) { 18 | return $UserGroupMember 19 | } 20 | else { 21 | throw "Invalid user group identifier '$UserGroupMember'. Must be either a [TeamViewerPS.UserGroupMember],[TeamViewerPS.User] or [int] ." 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Tests/Private/Test-PowershellFilesValidity.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | $Script:Module_RootPath = (Resolve-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath '..\..')) 3 | } 4 | 5 | Context 'Test-PowershellFilesValidity' { 6 | $TVPS_PSFiles = Get-ChildItem $Module_RootPath -Include *.ps1 -Recurse 7 | 8 | $Test_Case = $TVPS_PSFiles | ForEach-Object { 9 | @{ 10 | FilePath = $_.fullname 11 | FileName = $_.Name 12 | 13 | } 14 | } 15 | 16 | It 'Script should be a valid Powershell file' -TestCases $Test_Case { 17 | param( 18 | $FilePath 19 | ) 20 | 21 | $FilePath | Should -Exist 22 | 23 | $Test_FileContent = Get-Content -Path $FilePath -ErrorAction Stop 24 | 25 | $Test_Error = $null 26 | $null = [System.Management.Automation.PSParser]::Tokenize($Test_FileContent, [ref]$Test_Error) 27 | 28 | $Test_Error.Count | Should -Be 0 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerRole.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerRole { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | process { 8 | $properties = @{ 9 | RoleName = $InputObject.Name 10 | RoleID = $InputObject.Id 11 | } 12 | if ($InputObject.Permissions) { 13 | foreach ($permission in $InputObject.Permissions.PSObject.Properties) { 14 | $properties[$permission.Name] = $permission.Value 15 | } 16 | } 17 | $result = New-Object -TypeName PSObject -Property $properties 18 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.Role') 19 | $result | Add-Member -MemberType ScriptMethod -Name 'ToString' -Force -Value { 20 | Write-Output "[$($this.RoleName)] [$($this.RoleID)] $($this.Permissions))" 21 | } 22 | Write-Output $result 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Docs/Help/Get-TeamViewerInstallationDirectory.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Get-TeamViewerInstallationDirectory.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-TeamViewerInstallationDirectory 9 | 10 | ## SYNOPSIS 11 | 12 | Retrieves the TeamViewer installation directory. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Get-TeamViewerInstallationDirectory 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | The command checks the TeamViewer Installation and returns the installation directory. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS /> Get-TeamViewerInstallationDirectory 30 | ``` 31 | 32 | Returns the installation directory. 33 | 34 | ## PARAMETERS 35 | 36 | ### CommonParameters 37 | 38 | ### None 39 | 40 | ## INPUTS 41 | 42 | ### None 43 | 44 | ## OUTPUTS 45 | 46 | ## NOTES 47 | 48 | ## RELATED LINKS 49 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerGroup.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamViewerGroup { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerGroupId } )] 10 | [Alias("GroupId")] 11 | [Alias("Id")] 12 | [object] 13 | $Group 14 | ) 15 | Process { 16 | $groupId = $Group | Resolve-TeamViewerGroupId 17 | $resourceUri = "$(Get-TeamViewerApiUri)/groups/$groupId" 18 | 19 | if ($PSCmdlet.ShouldProcess($groupId, "Remove group")) { 20 | Invoke-TeamViewerRestMethod ` 21 | -ApiToken $ApiToken ` 22 | -Uri $resourceUri ` 23 | -Method Delete ` 24 | -WriteErrorTo $PSCmdlet | ` 25 | Out-Null 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerSsoExclusion.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerSsoExclusion { 2 | param( 3 | [Parameter(Mandatory = $true)] 4 | [securestring] 5 | $ApiToken, 6 | 7 | [Parameter(Mandatory = $true)] 8 | [ValidateScript( { $_ | Resolve-TeamViewerSsoDomainId } )] 9 | [Alias("Domain")] 10 | [object] 11 | $DomainId 12 | ) 13 | 14 | $id = $DomainId | Resolve-TeamViewerSsoDomainId 15 | $resourceUri = "$(Get-TeamViewerApiUri)/ssoDomain/$id/exclusion"; 16 | $parameters = @{ } 17 | do { 18 | $response = Invoke-TeamViewerRestMethod ` 19 | -ApiToken $ApiToken ` 20 | -Uri $resourceUri ` 21 | -Method Get ` 22 | -Body $parameters ` 23 | -WriteErrorTo $PSCmdlet ` 24 | -ErrorAction Stop 25 | 26 | Write-Output $response.emails 27 | $parameters.ct = $response.continuation_token 28 | } while ($parameters.ct) 29 | } 30 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerSsoInclusion.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerSsoInclusion { 2 | param( 3 | [Parameter(Mandatory = $true)] 4 | [securestring] 5 | $ApiToken, 6 | 7 | [Parameter(Mandatory = $true)] 8 | [ValidateScript( { $_ | Resolve-TeamViewerSsoDomainId } )] 9 | [Alias('Domain')] 10 | [object] 11 | $DomainId 12 | ) 13 | 14 | $id = $DomainId | Resolve-TeamViewerSsoDomainId 15 | $resourceUri = "$(Get-TeamViewerApiUri)/ssoDomain/$id/inclusion" 16 | $parameters = @{ } 17 | do { 18 | $response = Invoke-TeamViewerRestMethod ` 19 | -ApiToken $ApiToken ` 20 | -Uri $resourceUri ` 21 | -Method Get ` 22 | -Body $parameters ` 23 | -WriteErrorTo $PSCmdlet ` 24 | -ErrorAction Stop 25 | 26 | Write-Output $response.emails 27 | $parameters.ct = $response.continuation_token 28 | } while ($parameters.ct) 29 | } 30 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerRole.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamViewerRole { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerRoleId } )] 10 | [Alias('Role')] 11 | [Alias('Id')] 12 | [object] 13 | $RoleId 14 | ) 15 | 16 | Begin { 17 | $resourceUri = "$(Get-TeamViewerApiUri)/userroles?userRoleId=$RoleId" 18 | } 19 | 20 | Process { 21 | if ($PSCmdlet.ShouldProcess($RoleId.ToString(), 'Remove Role')) { 22 | Invoke-TeamViewerRestMethod ` 23 | -ApiToken $ApiToken ` 24 | -Uri $resourceUri ` 25 | -Method Delete ` 26 | -WriteErrorTo $PSCmdlet ` 27 | -ErrorAction Stop | ` 28 | Out-Null 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerUserTFA.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamViewerUserTFA { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerUserId } )] 10 | [Alias('UserId')] 11 | [Alias('Id')] 12 | [object] 13 | $User 14 | ) 15 | Process { 16 | $userId = $User | Resolve-TeamViewerUserId 17 | $resourceUri = "$(Get-TeamViewerApiUri)/users/$userId/tfa" 18 | 19 | 20 | if ($PSCmdlet.ShouldProcess($userId, 'Disable TFA')) { 21 | Invoke-TeamViewerRestMethod ` 22 | -ApiToken $ApiToken ` 23 | -Uri $resourceUri ` 24 | -Method Delete ` 25 | -WriteErrorTo $PSCmdlet | ` 26 | Out-Null 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerManagedDevice.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerManagedDevice { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | process { 8 | $properties = @{ 9 | Id = [guid]$InputObject.id 10 | Name = $InputObject.name 11 | TeamViewerId = $InputObject.TeamViewerId 12 | IsOnline = $InputObject.isOnline 13 | } 14 | 15 | if ($InputObject.last_seen) { 16 | $properties['LastSeenAt'] = Get-Date -Date $InputObject.last_seen 17 | } 18 | 19 | if ($InputObject.teamviewerPolicyId) { 20 | $properties["PolicyId"] = [guid]$InputObject.teamviewerPolicyId 21 | } 22 | 23 | $result = New-Object -TypeName PSObject -Property $properties 24 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.ManagedDevice') 25 | Write-Output $result 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Docs/Help/Remove-TeamViewerCustomization.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Remove-TeamViewerCustomization.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Remove-TeamViewerCustomization 9 | 10 | ## SYNOPSIS 11 | 12 | Removes the customization from the TeamViewer Installation. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Remove-TeamViewerCustomization 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Removes the existing customization from the TeamViewer Installation. 23 | Existing customization should be removed before applying new customization. 24 | 25 | ## EXAMPLES 26 | 27 | ### Example 1 28 | 29 | ```powershell 30 | PS /> Remove-TeamViewerAssignment 31 | ``` 32 | 33 | Removes the customization. 34 | 35 | ## PARAMETERS 36 | 37 | ### CommonParameters 38 | 39 | ### None 40 | 41 | ## INPUTS 42 | 43 | ## OUTPUTS 44 | 45 | ## NOTES 46 | 47 | ## RELATED LINKS 48 | -------------------------------------------------------------------------------- /Tests/Private/Test-PrivateFunctions.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | $Script:Module_RootPath = (Resolve-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath '..\..')) 3 | $Script:Module_FilePath = (Get-ChildItem -Path (Join-Path -Path $Module_RootPath -ChildPath 'Cmdlets') -Filter '*.psm1' -File).FullName 4 | $Script:Module_Name = (Split-Path -Path $Module_FilePath -Leaf).Replace('.psm1', '') 5 | $Script:Module_ManifestFilePath = (Get-ChildItem -Path (Join-Path -Path $Module_RootPath -ChildPath 'Cmdlets') -Filter '*.psd1' -File).FullName 6 | $Script:Module_PrivFunctionNames = (Get-ChildItem -Path (Join-Path -Path $Module_RootPath -ChildPath 'Cmdlets\Private') -Filter '*.ps1' -File | Select-Object BaseName) 7 | } 8 | 9 | Context 'Test-PrivateFunctions' { 10 | 11 | It 'Private functions not accessible from outside' { 12 | foreach ($PrivFunction in $Module_PrivFunctionNames.BaseName) { 13 | { . $PrivFunction } | Should -Throw 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerSsoDomain.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerSsoDomain { 2 | [CmdletBinding(DefaultParameterSetName = "FilteredList")] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(ParameterSetName = "ByDomainId")] 9 | [Alias("DomainId")] 10 | [guid] 11 | $Id 12 | ) 13 | 14 | $resourceUri = "$(Get-TeamViewerApiUri)/ssoDomain"; 15 | $parameters = @{ } 16 | switch ($PsCmdlet.ParameterSetName) { 17 | 'ByDomainId' { 18 | $resourceUri += "/$Id" 19 | $parameters = $null 20 | } 21 | } 22 | 23 | $response = Invoke-TeamViewerRestMethod ` 24 | -ApiToken $ApiToken ` 25 | -Uri $resourceUri ` 26 | -Method Get ` 27 | -Body $parameters ` 28 | -WriteErrorTo $PSCmdlet ` 29 | -ErrorAction Stop 30 | Write-Output ($response.domains | ConvertTo-TeamViewerSsoDomain) 31 | } 32 | -------------------------------------------------------------------------------- /Cmdlets/Public/New-TeamViewerManagedGroup.ps1: -------------------------------------------------------------------------------- 1 | function New-TeamViewerManagedGroup { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [string] 10 | $Name 11 | ) 12 | 13 | $body = @{ name = $Name } 14 | $resourceUri = "$(Get-TeamViewerApiUri)/managed/groups" 15 | if ($PSCmdlet.ShouldProcess($Name, "Create managed group")) { 16 | $response = Invoke-TeamViewerRestMethod ` 17 | -ApiToken $ApiToken ` 18 | -Uri $resourceUri ` 19 | -Method Post ` 20 | -ContentType "application/json; charset=utf-8" ` 21 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 22 | -WriteErrorTo $PSCmdlet ` 23 | -ErrorAction Stop 24 | Write-Output ($response | ConvertTo-TeamViewerManagedGroup) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerAuditEvent.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerAuditEvent { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | process { 8 | $properties = @{ 9 | Name = $InputObject.EventName 10 | Type = $InputObject.EventType 11 | Timestamp = $InputObject.Timestamp | ConvertTo-DateTime 12 | Author = $InputObject.Author 13 | AffectedItem = $InputObject.AffectedItem 14 | EventDetails = $InputObject.EventDetails 15 | } 16 | $result = New-Object -TypeName PSObject -Property $properties 17 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.AuditEvent') 18 | $result | Add-Member -MemberType ScriptMethod -Name "ToString" -Force -Value { 19 | Write-Output "[$($this.Timestamp)] $($this.Name) ($($this.Type))" 20 | } 21 | Write-Output $result 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerRestError.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerRestError { 2 | param( 3 | [parameter(ValueFromPipeline)] 4 | $InputError 5 | ) 6 | Process { 7 | try { 8 | $errorObject = ($InputError | Out-String | ConvertFrom-Json) 9 | $result = [PSCustomObject]@{ 10 | Message = $errorObject.error_description 11 | ErrorCategory = $errorObject.error 12 | ErrorCode = $errorObject.error_code 13 | ErrorSignature = $errorObject.error_signature 14 | } 15 | $result | Add-Member -MemberType ScriptMethod -Name 'ToString' -Force -Value { 16 | Write-Output "$($this.Message) ($($this.ErrorCategory))" 17 | } 18 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.RestError') 19 | return $result 20 | } 21 | catch { 22 | return $InputError 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerPolicy.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerPolicy { 2 | [CmdletBinding(DefaultParameterSetName = "FilteredList")] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(ParameterSetName = "ByPolicyId")] 9 | [Alias("PolicyId")] 10 | [guid] 11 | $Id 12 | ) 13 | 14 | $resourceUri = "$(Get-TeamViewerApiUri)/teamviewerpolicies"; 15 | $parameters = @{ } 16 | 17 | switch ($PsCmdlet.ParameterSetName) { 18 | 'ByPolicyId' { 19 | $resourceUri += "/$Id" 20 | $parameters = $null 21 | } 22 | } 23 | 24 | $response = Invoke-TeamViewerRestMethod ` 25 | -ApiToken $ApiToken ` 26 | -Uri $resourceUri ` 27 | -Method Get ` 28 | -Body $parameters ` 29 | -WriteErrorTo $PSCmdlet ` 30 | -ErrorAction Stop 31 | 32 | Write-Output ($response.policies | ConvertTo-TeamViewerPolicy) 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerManagementId.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerManagementId { 2 | if (Test-TeamViewerInstallation) { 3 | switch (Get-OperatingSystem) { 4 | 'Windows' { 5 | $regKeyPath = Join-Path (Get-TeamViewerRegKeyPath) 'DeviceManagementV2' 6 | $regKey = if (Test-Path -LiteralPath $regKeyPath) { Get-Item -Path $regKeyPath } 7 | if ($regKey) { 8 | $unmanaged = [bool]($regKey.GetValue('Unmanaged')) 9 | $managementId = $regKey.GetValue('ManagementId') 10 | } 11 | } 12 | 'Linux' { 13 | $unmanaged = [bool](Get-TeamViewerLinuxGlobalConfig -Name 'DeviceManagementV2\Unmanaged') 14 | $managementId = Get-TeamViewerLinuxGlobalConfig -Name 'DeviceManagementV2\ManagementId' 15 | } 16 | } 17 | if (!$unmanaged -And $managementId) { 18 | Write-Output ([guid]$managementId) 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerPolicy.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamViewerPolicy { 2 | [CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName = 'ByParameters')] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerPolicyId } )] 10 | [Alias('PolicyId')] 11 | [object] 12 | $Policy 13 | ) 14 | Process { 15 | $policyId = $Policy | Resolve-TeamViewerPolicyId 16 | $resourceUri = "$(Get-TeamViewerApiUri)/teamviewerpolicies/$policyId" 17 | 18 | if ($PSCmdlet.ShouldProcess($policyId, "Delete policy")) { 19 | Invoke-TeamViewerRestMethod ` 20 | -ApiToken $ApiToken ` 21 | -Uri $resourceUri ` 22 | -Method Delete ` 23 | -WriteErrorTo $PSCmdlet | ` 24 | Out-Null 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerManagedGroup.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamViewerManagedGroup { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerManagedGroupId } )] 10 | [Alias("GroupId")] 11 | [Alias("Id")] 12 | [object] 13 | $Group 14 | ) 15 | Process { 16 | $groupId = $Group | Resolve-TeamViewerManagedGroupId 17 | $resourceUri = "$(Get-TeamViewerApiUri)/managed/groups/$groupId" 18 | 19 | if ($PSCmdlet.ShouldProcess($groupId, "Remove managed group")) { 20 | Invoke-TeamViewerRestMethod ` 21 | -ApiToken $ApiToken ` 22 | -Uri $resourceUri ` 23 | -Method Delete ` 24 | -WriteErrorTo $PSCmdlet | ` 25 | Out-Null 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tests/Public/Set-TeamViewerPredefinedRole.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Set-TeamViewerPredefinedRole.ps1" 3 | 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ForEach-Object { . $_.FullName } 5 | 6 | $testApiToken = [securestring]@{} 7 | $null = $testApiToken 8 | $testRoleId = '9b465ea2-2f75-4101-a057-58a81ed0e57b' 9 | $null = $testRoleId 10 | 11 | Mock Get-TeamViewerApiUri { '//unit.test' } 12 | Mock Invoke-TeamViewerRestMethod 13 | } 14 | 15 | Describe 'Set-TeamViewerPredefinedRole' { 16 | It 'Should call the correct API endpoint' { 17 | Set-TeamViewerPredefinedRole -ApiToken $testApiToken -RoleId $testRoleId 18 | 19 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 20 | $ApiToken -eq $testApiToken -And ` 21 | $Uri -eq "//unit.test/userroles/$testRoleId/predefined" -And ` 22 | $Method -eq 'Put' 23 | } 24 | } 25 | 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerDevice.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamViewerDevice { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerDeviceId } )] 10 | [Alias("DeviceId")] 11 | [Alias("Id")] 12 | [object] 13 | $Device 14 | ) 15 | Process { 16 | $deviceId = $Device | Resolve-TeamViewerDeviceId 17 | $resourceUri = "$(Get-TeamViewerApiUri)/devices/$deviceId" 18 | if ($PSCmdlet.ShouldProcess($deviceId, "Remove device entry")) { 19 | Invoke-TeamViewerRestMethod ` 20 | -ApiToken $ApiToken ` 21 | -Uri $resourceUri ` 22 | -Method Delete ` 23 | -WriteErrorTo $PSCmdlet ` 24 | -ErrorAction Stop | ` 25 | Out-Null 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerContact.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamViewerContact { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerContactId } )] 10 | [Alias("ContactId")] 11 | [Alias("Id")] 12 | [object] 13 | $Contact 14 | ) 15 | Process { 16 | $contactId = $Contact | Resolve-TeamViewerContactId 17 | $resourceUri = "$(Get-TeamViewerApiUri)/contacts/$contactId" 18 | if ($PSCmdlet.ShouldProcess($contactId, "Remove contact")) { 19 | Invoke-TeamViewerRestMethod ` 20 | -ApiToken $ApiToken ` 21 | -Uri $resourceUri ` 22 | -Method Delete ` 23 | -WriteErrorTo $PSCmdlet ` 24 | -ErrorAction Stop | ` 25 | Out-Null 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerCustomization.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamViewerCustomization { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param() 4 | 5 | if (Get-OperatingSystem -eq 'Windows') { 6 | if (Test-TeamViewerInstallation) { 7 | $installationDirectory = Get-TeamViewerInstallationDirectory 8 | $currentDirectory = Get-Location 9 | Set-Location $installationDirectory 10 | $cmd = 'customize --remove' 11 | if ($PSCmdlet.ShouldProcess($installationDirectory, 'Remove Client Customization')) { 12 | $process = Start-Process -FilePath TeamViewer.exe -ArgumentList $cmd -Wait -PassThru 13 | $process.ExitCode | Resolve-CustomizationErrorCode 14 | } 15 | Set-Location $currentDirectory 16 | } 17 | else { 18 | Write-Error 'TeamViewer is not installed' 19 | } 20 | } 21 | else { 22 | Write-Error 'Customization is currently supported only on Windows.' 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Cmdlets/Public/Set-TeamViewerPredefinedRole.ps1: -------------------------------------------------------------------------------- 1 | function Set-TeamViewerPredefinedRole { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true, ValueFromPipeline = $true )] 9 | [ValidateScript({ $_ | Resolve-TeamViewerRoleId })] 10 | [object] 11 | $RoleId 12 | ) 13 | 14 | Process { 15 | $Role = $RoleId | Resolve-TeamViewerRoleId 16 | $resourceUri = "$(Get-TeamViewerApiUri)/userroles/$Role/predefined" 17 | if ($PSCmdlet.ShouldProcess($Role, 'Set Predefined Role')) { 18 | Invoke-TeamViewerRestMethod ` 19 | -ApiToken $ApiToken ` 20 | -Uri $resourceUri ` 21 | -Method Put ` 22 | -ContentType 'application/json; charset=utf-8' ` 23 | -WriteErrorTo $PSCmdlet ` 24 | -ErrorAction Stop | ` 25 | Out-Null 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerUserGroup.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamViewerUserGroup { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerUserGroupId } )] 10 | [Alias("UserGroupId")] 11 | [Alias("Id")] 12 | [object] 13 | $UserGroup 14 | ) 15 | 16 | Begin { 17 | $id = $UserGroup | Resolve-TeamViewerUserGroupId 18 | $resourceUri = "$(Get-TeamViewerApiUri)/usergroups/$id" 19 | } 20 | 21 | Process { 22 | if ($PSCmdlet.ShouldProcess($UserGroup.ToString(), "Remove user group")) { 23 | Invoke-TeamViewerRestMethod ` 24 | -ApiToken $ApiToken ` 25 | -Uri $resourceUri ` 26 | -Method Delete ` 27 | -WriteErrorTo $PSCmdlet ` 28 | -ErrorAction Stop | ` 29 | Out-Null 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerRole.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerRole { 2 | [CmdletBinding(DefaultParameterSetName = '')] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [switch] 9 | [Alias('ListPermissions')] 10 | $Permissions 11 | ) 12 | 13 | Begin { 14 | $parameters = @{ } 15 | $resourceUri = "$(Get-TeamViewerApiUri)/userroles" 16 | if ($Permissions) { 17 | $resourceUri += '/permissions' 18 | } 19 | } 20 | 21 | Process { 22 | $response = Invoke-TeamViewerRestMethod ` 23 | -ApiToken $ApiToken ` 24 | -Uri $resourceUri ` 25 | -Method Get ` 26 | -Body $parameters ` 27 | -WriteErrorTo $PSCmdlet ` 28 | -ErrorAction Stop 29 | if ($Permissions) { 30 | return [PSCustomObject] $response 31 | } 32 | else { 33 | Write-Output ($response.Roles | ConvertTo-TeamViewerRole ) 34 | } 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerManagedDeviceManagement.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamViewerManagedDeviceManagement { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerManagedDeviceId } )] 10 | [Alias('DeviceId')] 11 | [object] 12 | $Device 13 | ) 14 | Process { 15 | $deviceId = $Device | Resolve-TeamViewerManagedDeviceId 16 | 17 | $resourceUri = "$(Get-TeamViewerApiUri)/managed/devices/$deviceId" 18 | 19 | if ($PSCmdlet.ShouldProcess($deviceId, 'Remove Management from a device (clears all managers and groups)')) { 20 | Invoke-TeamViewerRestMethod ` 21 | -ApiToken $ApiToken ` 22 | -Uri $resourceUri ` 23 | -Method Delete ` 24 | -WriteErrorTo $PSCmdlet | ` 25 | Out-Null 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Cmdlets/Private/Resolve-TeamViewerLanguage.ps1: -------------------------------------------------------------------------------- 1 | function Resolve-TeamViewerLanguage { 2 | param( 3 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 4 | [object] 5 | $InputObject 6 | ) 7 | Process { 8 | $supportedLanguages = @( 9 | 'bg', 'cs', 'da', 'de', 'el', 'en', 'es', 'fi', 'fr', 'hr', 'hu', 'id', 'it', 'ja', 10 | 'ko', 'lt', 'nl', 'no', 'pl', 'pt', 'ro', 'ru', 'sk', 'sr', 'sv', 'th', 'tr', 'uk', 11 | 'vi', 'zh_CN', 'zh_TW', 'auto') 12 | 13 | $language = $InputObject 14 | if ($InputObject -is [cultureinfo]) { 15 | $language = switch ($InputObject.Name) { 16 | 'zh-CN' { 'zh_CN' } 17 | 'zh-TW' { 'zh_TW' } 18 | default { $InputObject.TwoLetterISOLanguageName } 19 | } 20 | } 21 | 22 | if ($supportedLanguages -notcontains $language) { 23 | throw "Invalid culture '$language'. Supported languages are: $supportedLanguages" 24 | } 25 | 26 | return $language 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerUserByRole.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerUserByRole { 2 | param( 3 | [Parameter(Mandatory = $true)] 4 | [securestring] 5 | $ApiToken, 6 | 7 | [Parameter(Mandatory = $true)] 8 | [ValidateScript( { $_ | Resolve-TeamViewerRoleId } )] 9 | [Alias('Role')] 10 | [string] 11 | $RoleId 12 | ) 13 | 14 | 15 | $resourceUri = "$(Get-TeamViewerApiUri)/userroles/assignments/account?userRoleId=$RoleId" 16 | $parameters = $null 17 | do { 18 | $response = Invoke-TeamViewerRestMethod ` 19 | -ApiToken $ApiToken ` 20 | -Uri $resourceUri ` 21 | -Method Get ` 22 | -Body $parameters ` 23 | -WriteErrorTo $PSCmdlet ` 24 | -ErrorAction Stop 25 | if ($response.ContinuationToken) { 26 | $resourceUri += '&continuationToken=' + $response.ContinuationToken 27 | } 28 | Write-Output ($response.AssignedToUsers | ConvertTo-TeamViewerRoleAssignedUser ) 29 | }while ($response.ContinuationToken) 30 | } 31 | -------------------------------------------------------------------------------- /.github/workflows/publish_production.yml: -------------------------------------------------------------------------------- 1 | name: Publish_Production 2 | 3 | on: 4 | workflow_dispatch: 5 | release: 6 | types: [published] 7 | 8 | jobs: 9 | publish: 10 | runs-on: windows-latest 11 | 12 | steps: 13 | # Checks-out the repository under $GITHUB_WORKSPACE, so the job can access it 14 | - uses: actions/checkout@v3 15 | 16 | # Build package 17 | - name: Build package 18 | shell: pwsh 19 | run: | 20 | $ProgressPreference='SilentlyContinue' 21 | Install-Module platyPS,BuildHelpers -Force -SkipPublisherCheck -Scope CurrentUser 22 | & $env:GITHUB_WORKSPACE/Build/New-Package.ps1 -Verbose 23 | 24 | # Publish to PowershellGallery.com 25 | - name: Publish to PowershellGallery.com 26 | env: 27 | NUGET_APIKEY_PRODUCTION: ${{ secrets.NUGET_APIKEY_PRODUCTION }} 28 | shell: pwsh 29 | run: | 30 | $ProgressPreference='SilentlyContinue' 31 | Publish-Module -Path $env:GITHUB_WORKSPACE/Build/TeamViewerPS/ -NuGetApiKey $env:NUGET_APIKEY_PRODUCTION 32 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerContact.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerContact { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | process { 8 | $properties = @{ 9 | Id = $InputObject.contact_id 10 | UserId = $InputObject.user_id 11 | GroupId = $InputObject.groupid 12 | Name = $InputObject.name 13 | Description = $InputObject.description 14 | OnlineState = $InputObject.online_state 15 | ProfilePictureUrl = $InputObject.profilepicture_url 16 | SupportedFeatures = $InputObject.supported_features 17 | } 18 | $result = New-Object -TypeName PSObject -Property $properties 19 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.Contact') 20 | $result | Add-Member -MemberType ScriptMethod -Name "ToString" -Force -Value { 21 | Write-Output "$($this.Name)" 22 | } 23 | Write-Output $result 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Cmdlets/Public/New-TeamViewerUserGroup.ps1: -------------------------------------------------------------------------------- 1 | function New-TeamViewerUserGroup { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [string] 10 | $Name 11 | ) 12 | 13 | Begin { 14 | $resourceUri = "$(Get-TeamViewerApiUri)/usergroups" 15 | $body = @{ name = $Name } 16 | } 17 | 18 | Process { 19 | if ($PSCmdlet.ShouldProcess($Name, "Create user group")) { 20 | $response = Invoke-TeamViewerRestMethod ` 21 | -ApiToken $ApiToken ` 22 | -Uri $resourceUri ` 23 | -Method Post ` 24 | -ContentType "application/json; charset=utf-8" ` 25 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 26 | -WriteErrorTo $PSCmdlet ` 27 | -ErrorAction Stop 28 | Write-Output ($response | ConvertTo-TeamViewerUserGroup) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerAssignment.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamViewerAssignment { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param() 4 | 5 | 6 | if (Test-TeamViewerInstallation) { 7 | $OS = Get-OperatingSystem 8 | $CurrentDirectory = Get-Location 9 | $installationDirectory = Get-TeamViewerInstallationDirectory 10 | Set-Location $installationDirectory 11 | if ($OS -eq 'Windows') { 12 | $cmd = 'unassign' 13 | $FilePath = 'TeamViewer.exe' 14 | } 15 | elseif ($OS -eq 'Linux') { 16 | $cmd = 'teamviewer unassign' 17 | $FilePath = 'sudo' 18 | } 19 | if ($PSCmdlet.ShouldProcess($installationDirectory, 'Remove device assignment')) { 20 | $process = Start-Process -FilePath $FilePath -ArgumentList $cmd -Wait -PassThru 21 | $process.ExitCode | Resolve-AssignmentErrorCode 22 | Set-Location $CurrentDirectory 23 | } 24 | } 25 | else { 26 | Write-Output 'TeamViewer is not installed.' 27 | } 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /Tests/Public/Test-TeamViewerInstallation.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Get-TeamViewerInstallationDirectory.ps1" 3 | . "$PSScriptRoot\..\..\Cmdlets\Public\Test-TeamViewerInstallation.ps1" 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 5 | ForEach-Object { . $_.FullName } 6 | } 7 | 8 | Describe 'Test-TeamViewerInstallation' { 9 | Context 'TeamViewer installed' { 10 | BeforeAll { 11 | Mock Get-TeamViewerInstallationDirectory { 'C:\Program Files\TeamViewer' } 12 | } 13 | 14 | It 'Should return true if TeamViewer is installed' { 15 | $result = Test-TeamViewerInstallation 16 | $result | Should -Be $true 17 | } 18 | } 19 | 20 | Context 'TeamViewer not installed' { 21 | BeforeAll { 22 | Mock Get-TeamViewerInstallationDirectory { $null } 23 | } 24 | 25 | It 'Should return false if TeamViewer is not installed' { 26 | $result = Test-TeamViewerInstallation 27 | $result | Should -Be $false 28 | } 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerUser.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamViewerUser { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerUserId } )] 10 | [Alias("UserId")] 11 | [Alias("Id")] 12 | [object] 13 | $User, 14 | 15 | [Parameter()] 16 | [switch] 17 | $Permanent 18 | ) 19 | Process { 20 | $userId = $User | Resolve-TeamViewerUserId 21 | $resourceUri = "$(Get-TeamViewerApiUri)/users/$userId" 22 | 23 | if ($Permanent) { 24 | $resourceUri += '?isPermanentDelete=true' 25 | } 26 | 27 | if ($PSCmdlet.ShouldProcess($userId, "Remove user")) { 28 | Invoke-TeamViewerRestMethod ` 29 | -ApiToken $ApiToken ` 30 | -Uri $resourceUri ` 31 | -Method Delete ` 32 | -WriteErrorTo $PSCmdlet | ` 33 | Out-Null 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Cmdlets/Private/Resolve-TeamViewerPolicyId.ps1: -------------------------------------------------------------------------------- 1 | function Resolve-TeamViewerPolicyId { 2 | param( 3 | [Parameter(ValueFromPipeline = $true, Mandatory = $true)] 4 | [object] 5 | $Policy, 6 | 7 | [Parameter()] 8 | [switch] 9 | $AllowNone, 10 | 11 | [Parameter()] 12 | [switch] 13 | $AllowInherit 14 | ) 15 | Process { 16 | if ($Policy.PSObject.TypeNames -contains 'TeamViewerPS.Policy') { 17 | return [guid]$Policy.Id 18 | } 19 | elseif ($Policy -is [string]) { 20 | if ($Policy -eq 'none' -And $AllowNone) { 21 | return 'none' 22 | } 23 | elseif ($Policy -eq 'inherit' -And $AllowInherit) { 24 | return 'inherit' 25 | } 26 | else { 27 | return [guid]$Policy 28 | } 29 | } 30 | elseif ($Policy -is [guid]) { 31 | return $Policy 32 | } 33 | else { 34 | throw "Invalid policy identifier '$Policy'. Must be either a [TeamViewerPS.Policy], [guid] or [string]." 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018-2025 TeamViewer Germany GmbH 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerAccount.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerAccount { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | process { 8 | $properties = @{ 9 | Name = $InputObject.name 10 | Email = $InputObject.email 11 | UserId = $InputObject.userid 12 | CompanyName = $InputObject.company_name 13 | IsEmailValidated = $InputObject.email_validated 14 | EmailLanguage = $InputObject.email_language 15 | } 16 | if ($InputObject.email_language -And $InputObject.email_language -Ne 'auto') { 17 | $properties["EmailLanguage"] = [System.Globalization.CultureInfo]($InputObject.email_language) 18 | } 19 | $result = New-Object -TypeName PSObject -Property $properties 20 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.Account') 21 | $result | Add-Member -MemberType ScriptMethod -Name "ToString" -Force -Value { 22 | Write-Output "$($this.Name) <$($this.Email)>" 23 | } 24 | Write-Output $result 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerUserGroupByRole.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerUserGroupByRole { 2 | param( 3 | [Parameter(Mandatory = $true)] 4 | [securestring] 5 | $ApiToken, 6 | 7 | [Parameter(Mandatory = $true)] 8 | [ValidateScript({ $_ | Resolve-TeamViewerRoleId })] 9 | [Alias('Role')] 10 | [string] 11 | $RoleId 12 | ) 13 | 14 | Begin { 15 | $resourceUri = "$(Get-TeamViewerApiUri)/userroles/assignments/usergroups?userRoleId=$RoleId" 16 | $parameters = $null 17 | } 18 | Process { 19 | do { 20 | $response = Invoke-TeamViewerRestMethod ` 21 | -ApiToken $ApiToken ` 22 | -Uri $resourceUri ` 23 | -Method Get ` 24 | -Body $parameters ` 25 | -WriteErrorTo $PSCmdlet ` 26 | -ErrorAction Stop 27 | if ($response.ContinuationToken) { 28 | $resourceUri += '&continuationToken=' + $response.ContinuationToken 29 | } 30 | Write-Output ($response.AssignedToGroups | ConvertTo-TeamViewerRoleAssignedUserGroup ) 31 | }while ($response.ContinuationToken) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Docs/Help/Get-TeamViewerVersion.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Get-TeamViewerVersion.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-TeamViewerVersion 9 | 10 | ## SYNOPSIS 11 | 12 | Retrieve the installed version of TeamViewer. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Get-TeamViewerVersion [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Returns the version of TeamViewer that is installed on this machine. 23 | Nothing is returned if TeamViewer is not installed. 24 | 25 | ## EXAMPLES 26 | 27 | ### Example 1 28 | 29 | ```powershell 30 | PS /> Get-TeamViewerVersion 31 | ``` 32 | 33 | ## PARAMETERS 34 | 35 | ### CommonParameters 36 | 37 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 38 | 39 | ## INPUTS 40 | 41 | ### None 42 | 43 | ## OUTPUTS 44 | 45 | ## NOTES 46 | 47 | ## RELATED LINKS 48 | -------------------------------------------------------------------------------- /Tests/Public/Remove-TeamViewerPSProxy.Tests.ps1: -------------------------------------------------------------------------------- 1 | 2 | BeforeAll { 3 | . "$PSScriptRoot\..\..\Cmdlets\Public\Remove-TeamViewerPSProxy.ps1" 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 5 | ForEach-Object { . $_.FullName } 6 | 7 | Mock -CommandName 'Remove-TeamViewerPSProxy' -MockWith { 8 | $global:TeamViewerProxyUriSet = $null 9 | $global:TeamViewerProxyUriSet | Out-Null 10 | $global:TeamViewerProxyUriRemoved = $true 11 | $global:TeamViewerProxyUriRemoved | Out-Null 12 | [Environment]::SetEnvironmentVariable('TVProxyUri', '', 'User') 13 | } 14 | } 15 | 16 | Describe "Remove-TeamViewerPSProxy" { 17 | Context "When removing the proxy URI" { 18 | It "Should set the global variable TeamViewerProxyUriRemoved to true" { 19 | Remove-TeamViewerPSProxy 20 | $global:TeamViewerProxyUriRemoved | Should -Be $true 21 | } 22 | 23 | It "Should remove the environment variable TeamViewerProxyUri" { 24 | Remove-TeamViewerPSProxy 25 | [Environment]::GetEnvironmentVariable("TVProxyUri", "User") | Should -BeNullOrEmpty 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerUserGroupMember.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerUserGroupMember { 2 | [CmdletBinding()] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerUserGroupId } )] 10 | [Alias("UserGroupId")] 11 | [Alias("Id")] 12 | [object] 13 | $UserGroup 14 | ) 15 | 16 | Begin { 17 | $id = $UserGroup | Resolve-TeamViewerUserGroupId 18 | $resourceUri = "$(Get-TeamViewerApiUri)/usergroups/$id/members" 19 | $parameters = @{ } 20 | } 21 | 22 | Process { 23 | do { 24 | $response = Invoke-TeamViewerRestMethod ` 25 | -ApiToken $ApiToken ` 26 | -Uri $resourceUri ` 27 | -Method Get ` 28 | -Body $parameters ` 29 | -WriteErrorTo $PSCmdlet ` 30 | -ErrorAction Stop 31 | $parameters.paginationToken = $response.nextPaginationToken 32 | Write-Output ($response.resources | ConvertTo-TeamViewerUserGroupMember) 33 | } while ($parameters.paginationToken) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Cmdlets/Private/Test-TcpConnection.ps1: -------------------------------------------------------------------------------- 1 | $hasTestNetConnection = [bool](Get-Command Test-NetConnection -ErrorAction SilentlyContinue) 2 | $hasTestConnection = [bool](Get-Command Test-Connection -ErrorAction SilentlyContinue | Where-Object { $_.Version -ge 5.1 }) 3 | 4 | function Test-TcpConnection { 5 | param( 6 | [Parameter(Mandatory = $true)] 7 | [string] 8 | $Hostname, 9 | 10 | [Parameter(Mandatory = $true)] 11 | [int] 12 | $Port 13 | ) 14 | 15 | if (-Not $hasTestNetConnection -And -Not $hasTestConnection) { 16 | throw "No suitable cmdlet found for testing the TeamViewer network connectivity." 17 | } 18 | 19 | $oldProgressPreference = $global:ProgressPreference 20 | $global:ProgressPreference = 'SilentlyContinue' 21 | 22 | if ($hasTestNetConnection) { 23 | Test-NetConnection -ComputerName $Hostname -Port $Port -InformationLevel Quiet -WarningAction SilentlyContinue 24 | } 25 | elseif ($hasTestConnection) { 26 | Test-Connection -TargetName $Hostname -TcpPort $Port -Quiet -WarningAction SilentlyContinue 27 | } 28 | else { 29 | $false 30 | } 31 | 32 | $global:ProgressPreference = $oldProgressPreference 33 | } 34 | -------------------------------------------------------------------------------- /Cmdlets/Public/New-TeamViewerGroup.ps1: -------------------------------------------------------------------------------- 1 | function New-TeamViewerGroup { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [string] 10 | $Name, 11 | 12 | [Parameter()] 13 | [ValidateScript( { $_ | Resolve-TeamViewerPolicyId } )] 14 | [Alias("PolicyId")] 15 | [object] 16 | $Policy 17 | ) 18 | 19 | $body = @{ name = $Name } 20 | if ($Policy) { 21 | $body["policy_id"] = $Policy | Resolve-TeamViewerPolicyId 22 | } 23 | 24 | $resourceUri = "$(Get-TeamViewerApiUri)/groups" 25 | if ($PSCmdlet.ShouldProcess($Name, "Create group")) { 26 | $response = Invoke-TeamViewerRestMethod ` 27 | -ApiToken $ApiToken ` 28 | -Uri $resourceUri ` 29 | -Method Post ` 30 | -ContentType "application/json; charset=utf-8" ` 31 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 32 | -WriteErrorTo $PSCmdlet ` 33 | -ErrorAction Stop 34 | Write-Output ($response | ConvertTo-TeamViewerGroup) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Docs/Help/Test-TeamViewerInstallation.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Test-TeamViewerInstallation.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Test-TeamViewerInstallation 9 | 10 | ## SYNOPSIS 11 | 12 | Check if TeamViewer is installed on this machine. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Test-TeamViewerInstallation [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Test if TeamViewer is installed on this machine. 23 | The command simply returns `True` if installed, or `False` otherwise. 24 | 25 | ## EXAMPLES 26 | 27 | ### Example 1 28 | 29 | ```powershell 30 | PS /> Test-TeamViewerInstallation 31 | ``` 32 | 33 | ## PARAMETERS 34 | 35 | ### CommonParameters 36 | 37 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 38 | 39 | ## INPUTS 40 | 41 | ### None 42 | 43 | ## OUTPUTS 44 | 45 | ## NOTES 46 | 47 | ## RELATED LINKS 48 | -------------------------------------------------------------------------------- /Cmdlets/Public/Unpublish-TeamViewerGroup.ps1: -------------------------------------------------------------------------------- 1 | function Unpublish-TeamViewerGroup { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerGroupId } )] 10 | [Alias("GroupId")] 11 | [object] 12 | $Group, 13 | 14 | [Parameter(Mandatory = $true)] 15 | [Alias("UserId")] 16 | [object[]] 17 | $User 18 | ) 19 | 20 | $groupId = $Group | Resolve-TeamViewerGroupId 21 | $userIds = $User | Resolve-TeamViewerUserId 22 | $resourceUri = "$(Get-TeamViewerApiUri)/groups/$groupId/unshare_group" 23 | $body = @{users = @($userIds) } 24 | 25 | if ($PSCmdlet.ShouldProcess($userids, "Remove group share")) { 26 | Invoke-TeamViewerRestMethod ` 27 | -ApiToken $ApiToken ` 28 | -Uri $resourceUri ` 29 | -Method Post ` 30 | -ContentType "application/json; charset=utf-8" ` 31 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 32 | -WriteErrorTo $PSCmdlet | ` 33 | Out-Null 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Docs/Help/Get-TeamViewerId.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Get-TeamViewerId.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-TeamViewerId 9 | 10 | ## SYNOPSIS 11 | 12 | Returns the TeamViewer ID of the locally installed TeamViewer. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Get-TeamViewerId [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Returns the TeamViewer ID of the locally installed TeamViewer. This ID can be 23 | used to connect to this machine. 24 | Returns nothing if TeamViewer is not installed on this machine. 25 | 26 | ## EXAMPLES 27 | 28 | ### Example 1 29 | 30 | ```powershell 31 | PS /> $tvid = Get-TeamViewerId 32 | ``` 33 | 34 | ## PARAMETERS 35 | 36 | ### CommonParameters 37 | 38 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 39 | 40 | ## INPUTS 41 | 42 | ### None 43 | 44 | ## OUTPUTS 45 | 46 | ## NOTES 47 | 48 | ## RELATED LINKS 49 | -------------------------------------------------------------------------------- /Docs/Help/Get-TeamViewerManagementId.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Get-TeamViewerManagementId.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-TeamViewerManagementId 9 | 10 | ## SYNOPSIS 11 | 12 | Returns the TeamViewer Management ID of the locally installed TeamViewer. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Get-TeamViewerManagementId 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Returns the TeamViewer Management ID of the locally installed TeamViewer if the 23 | device is managed in the Managed Groups system. 24 | Returns nothing if either TeamViewer is not installed or the device is not a 25 | managed device in the Managed Groups system. 26 | For example, the management ID can be used as `DeviceId` for the 27 | `Get-TeamViewerManagedDevice` command (and all other Managed Device/Group 28 | related commands). 29 | 30 | ## EXAMPLES 31 | 32 | ### Example 1 33 | 34 | ```powershell 35 | PS /> Get-TeamViewerManagementId 36 | ``` 37 | 38 | ## PARAMETERS 39 | 40 | ## INPUTS 41 | 42 | ### None 43 | 44 | ## OUTPUTS 45 | 46 | ## NOTES 47 | 48 | ## RELATED LINKS 49 | 50 | [Get-TeamViewerManagedDevice](Get-TeamViewerManagedDevice.md) 51 | -------------------------------------------------------------------------------- /Cmdlets/Public/New-TeamViewerPolicy.ps1: -------------------------------------------------------------------------------- 1 | function New-TeamViewerPolicy { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [string] 10 | $Name, 11 | 12 | [Parameter()] 13 | [AllowEmptyCollection()] 14 | [object[]] 15 | $Settings, 16 | 17 | [Parameter()] 18 | [switch] 19 | $DefaultPolicy = $False 20 | ) 21 | 22 | $body = @{ 23 | name = $Name 24 | default = [boolean]$DefaultPolicy 25 | settings = @() 26 | } 27 | 28 | if ($Settings) { 29 | $body.settings = @($Settings) 30 | } 31 | 32 | $resourceUri = "$(Get-TeamViewerApiUri)/teamviewerpolicies" 33 | if ($PSCmdlet.ShouldProcess($Name, "Create policy")) { 34 | Invoke-TeamViewerRestMethod ` 35 | -ApiToken $ApiToken ` 36 | -Uri $resourceUri ` 37 | -Method Post ` 38 | -ContentType "application/json; charset=utf-8" ` 39 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 40 | -WriteErrorTo $PSCmdlet | ` 41 | Out-Null 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Docs/Help/Disconnect-TeamViewerApi.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Disconnect-TeamViewerApi.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Disconnect-TeamViewerApi 9 | 10 | ## SYNOPSIS 11 | 12 | Removes the TeamViewer API access token from the current environment. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Disconnect-TeamViewerApi [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Removes a possibly stored TeamViewer API access token from the current 23 | Powershell global scope. 24 | 25 | ## EXAMPLES 26 | 27 | ### Example 1 28 | 29 | ```powershell 30 | PS /> Disconnect-TeamViewerApi 31 | ``` 32 | 33 | ## PARAMETERS 34 | 35 | ### CommonParameters 36 | 37 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 38 | 39 | ## INPUTS 40 | 41 | ### None 42 | 43 | ## OUTPUTS 44 | 45 | ## NOTES 46 | 47 | ## RELATED LINKS 48 | 49 | [Connect-TeamViewerApi](Connect-TeamViewerApi.md) 50 | -------------------------------------------------------------------------------- /Tests/Public/Connect-TeamViewerApi.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Invoke-TeamViewerPing.ps1" 3 | . "$PSScriptRoot\..\..\Cmdlets\Public\Connect-TeamViewerApi.ps1" 4 | 5 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 6 | ForEach-Object { . $_.FullName } 7 | 8 | $testApiToken = [securestring]@{} 9 | $null = $testApiToken 10 | 11 | Mock Invoke-TeamViewerPing { $true } 12 | } 13 | 14 | Describe 'Connect-TeamViewerApi' { 15 | BeforeEach { 16 | $global:PSDefaultParameterValues.Clear() 17 | } 18 | 19 | It 'Should set the PSDefaultParameterValues for the TeamViewer cmdlets' { 20 | Connect-TeamViewerApi -ApiToken $testApiToken 21 | $global:PSDefaultParameterValues["*-Teamviewer*:ApiToken"] | Should -Be $testApiToken 22 | 23 | Assert-MockCalled Invoke-TeamViewerPing -Scope It -Times 1 -ParameterFilter { 24 | $ApiToken -eq $testApiToken 25 | } 26 | } 27 | 28 | It 'Should not set PSDefaultParameterValues if ping fails' { 29 | Mock Invoke-TeamViewerPing { $false } 30 | Connect-TeamViewerApi -ApiToken $testApiToken 31 | $global:PSDefaultParameterValues["*-Teamviewer*:ApiToken"] | Should -BeNullOrEmpty 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Tests/Public/New-TeamViewerGroup.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\New-TeamViewerGroup.ps1" 3 | 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 5 | ForEach-Object { . $_.FullName } 6 | 7 | $testApiToken = [securestring]@{} 8 | $null = $testApiToken 9 | $mockArgs = @{} 10 | 11 | Mock Get-TeamViewerApiUri { '//unit.test' } 12 | Mock Invoke-TeamViewerRestMethod { $mockArgs.Body = $Body } 13 | } 14 | 15 | Describe 'New-TeamViewerGroup' { 16 | 17 | It 'Should call the correct API endpoint' { 18 | New-TeamViewerGroup -ApiToken $testApiToken -Name 'Unit Test Group' 19 | 20 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 21 | $ApiToken -eq $testApiToken -And ` 22 | $Uri -eq '//unit.test/groups' -And ` 23 | $Method -eq 'Post' } 24 | } 25 | 26 | It 'Should include the given name in the request' { 27 | New-TeamViewerGroup -ApiToken $testApiToken -Name 'Unit Test Group' 28 | 29 | $mockArgs.Body | Should -Not -BeNullOrEmpty 30 | $body = [System.Text.Encoding]::UTF8.GetString($mockArgs.Body) | ConvertFrom-Json 31 | $body.name | Should -Be 'Unit Test Group' 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerManagedDevice.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamViewerManagedDevice { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerManagedDeviceId } )] 10 | [Alias("DeviceId")] 11 | [object] 12 | $Device, 13 | 14 | [Parameter(Mandatory = $true)] 15 | [ValidateScript( { $_ | Resolve-TeamViewerManagedGroupId } )] 16 | [Alias("GroupId")] 17 | [object] 18 | $Group 19 | ) 20 | Process { 21 | $deviceId = $Device | Resolve-TeamViewerManagedDeviceId 22 | $groupId = $Group | Resolve-TeamViewerManagedGroupId 23 | 24 | $resourceUri = "$(Get-TeamViewerApiUri)/managed/groups/$groupId/devices/$deviceId" 25 | 26 | if ($PSCmdlet.ShouldProcess($deviceId, "Remove device from managed group")) { 27 | Invoke-TeamViewerRestMethod ` 28 | -ApiToken $ApiToken ` 29 | -Uri $resourceUri ` 30 | -Method Delete ` 31 | -WriteErrorTo $PSCmdlet | ` 32 | Out-Null 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Tests/Public/Invoke-TeamViewerPing.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Invoke-TeamViewerPing.ps1" 3 | 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 5 | ForEach-Object { . $_.FullName } 6 | 7 | $testApiToken = [securestring]@{} 8 | $null = $testApiToken 9 | 10 | Mock Get-TeamViewerApiUri { '//unit.test' } 11 | Mock Invoke-TeamViewerRestMethod { @{ token_valid = $true } } 12 | } 13 | 14 | Describe 'Invoke-TeamViewerPing' { 15 | 16 | It 'Should call the correct API endpoint' { 17 | Invoke-TeamViewerPing -ApiToken $testApiToken 18 | 19 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 20 | $ApiToken -eq $testApiToken -And ` 21 | $Uri -eq '//unit.test/ping' -And ` 22 | $Method -eq 'Get' } 23 | } 24 | 25 | It 'Should evaluate the token validity' { 26 | Mock Invoke-TeamViewerRestMethod { @{ token_valid = $true } } 27 | $result = Invoke-TeamViewerPing -ApiToken $testApiToken 28 | $result | Should -Be $true 29 | 30 | Mock Invoke-TeamViewerRestMethod { @{ token_valid = $false } } 31 | $result = Invoke-TeamViewerPing -ApiToken $testApiToken 32 | $result | Should -Be $false 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerUserGroupFromRole.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamViewerUserGroupFromRole { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerUserGroupId } )] 10 | [Alias('UserGroupId')] 11 | [Alias('Id')] 12 | [object] 13 | $UserGroup 14 | ) 15 | 16 | Begin { 17 | $null = $ApiToken 18 | $resourceUri = "$(Get-TeamViewerApiUri)/userroles/unassign/usergroup" 19 | $body = @{ 20 | UserGroupId = $UserGroup 21 | } 22 | } 23 | 24 | 25 | Process { 26 | if ($PSCmdlet.ShouldProcess($UserGroupId, 'Unassign User Group from user role')) { 27 | $result = Invoke-TeamViewerRestMethod ` 28 | -ApiToken $ApiToken ` 29 | -Uri $resourceUri ` 30 | -Method Post ` 31 | -ContentType 'application/json; charset=utf-8' ` 32 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 33 | -WriteErrorTo $PSCmdlet ` 34 | -ErrorAction Stop 35 | Write-Output ($result) 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Cmdlets/Private/Get-TypeAndValueOfRegistryValue.ps1: -------------------------------------------------------------------------------- 1 | function Get-TypeAndValueOfRegistryValue { 2 | param ( 3 | [Microsoft.Win32.RegistryKey]$RegKey, 4 | [string]$ValueName 5 | ) 6 | 7 | $valueKind = $RegKey.GetValueKind($ValueName) 8 | $type = $valueKind 9 | 10 | if ($valueKind -eq 'DWord') { 11 | $type = "=dword:" 12 | $value = [Convert]::ToInt32($RegKey.GetValue($ValueName)).ToString('x') 13 | } 14 | elseif ($valueKind -eq 'Binary') { 15 | $type = "=hex:" 16 | $value = ($RegKey.GetValue($ValueName) | ForEach-Object { $_.ToString('x2') }) -join ',' 17 | } 18 | elseif ($valueKind -eq 'String') { 19 | $type = "=" 20 | $value = $RegKey.GetValue($ValueName).ToString() 21 | } 22 | elseif ($valueKind -eq 'MultiString') { 23 | $type = "=hex(7):" 24 | $value += ($RegKey.GetValue($ValueName) | ForEach-Object { 25 | $_.ToCharArray() | ForEach-Object { [Convert]::ToInt32($_).ToString('X') + ',00' } 26 | }) -join ',' 27 | $value += ',00,00,' 28 | if ($value.Length -gt 0) { 29 | $value += '00,00' 30 | } 31 | } 32 | else { 33 | $type = "" 34 | $value = $RegKey.GetValue($ValueName).ToString() 35 | } 36 | 37 | return $type, $value 38 | } 39 | 40 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerRoleByUserGroup.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerRoleByUserGroup { 2 | param( 3 | [Parameter(Mandatory = $true)] 4 | [securestring] 5 | $ApiToken, 6 | 7 | [Parameter(Mandatory = $true)] 8 | [ValidateScript({ $_ | Resolve-TeamViewerUserGroupId })] 9 | [Alias('UserGroupId')] 10 | [Alias('Id')] 11 | [string] 12 | $GroupId 13 | ) 14 | 15 | Begin { 16 | $resourceUri = "$(Get-TeamViewerApiUri)/usergroups/$GroupId/userroles" 17 | $parameters = $null 18 | } 19 | Process { 20 | do { 21 | $response = Invoke-TeamViewerRestMethod ` 22 | -ApiToken $ApiToken ` 23 | -Uri $resourceUri ` 24 | -Method Get ` 25 | -Body $parameters ` 26 | -WriteErrorTo $PSCmdlet ` 27 | -ErrorAction Stop 28 | if ($response.ContinuationToken) { 29 | $resourceUri += '&continuationToken=' + $response.ContinuationToken 30 | } 31 | if ($null -eq $response.assignedRoleId) { 32 | return $null 33 | } 34 | Write-Output ($response.assignedRoleId | ConvertTo-TeamViewerRoleAssignedUserGroup ) 35 | }while ($response.ContinuationToken) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Docs/Help/Get-TeamViewerLogFilePath.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Get-TeamViewerLogFilePath 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-TeamViewerLogFilePath 9 | 10 | ## SYNOPSIS 11 | 12 | Retrieves TeamViewer log files. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Get-TeamViewerLogFilePath -OpenFile 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | The command checks the required directories and returns the paths for log files. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS /> Get-TeamViewerLogFilePath 30 | ``` 31 | 32 | Returns the paths for log files. 33 | 34 | ### Example 2 35 | 36 | ```powershell 37 | PS /> Get-TeamViewerLogFilePath -OpenFile 38 | ``` 39 | 40 | Provides a prompt with choice to open the located files. 41 | 42 | ## PARAMETERS 43 | 44 | ### -OpenFile 45 | 46 | Switch to open a log file. 47 | 48 | ```yaml 49 | Type: switch 50 | Parameter Sets: (All) 51 | Aliases: None 52 | 53 | Required: False 54 | Position: 0 55 | Default value: None 56 | Accept pipeline input: False 57 | Accept wildcard characters: False 58 | ``` 59 | 60 | ### CommonParameters 61 | 62 | ### None 63 | 64 | ## INPUTS 65 | 66 | ## OUTPUTS 67 | 68 | ## NOTES 69 | 70 | ## RELATED LINKS 71 | -------------------------------------------------------------------------------- /Docs/Help/Set-TeamViewerPSProxy.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Set-TeamViewerPSProxy.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Set-TeamViewerPSProxy 9 | 10 | ## SYNOPSIS 11 | 12 | Set TeamViewerPS to use proxy. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Set-TeamViewerPSProxy [-ProxyUri] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Sets a Proxy to access webAPI for TeamViewerPS module functions. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS /> Set-TeamViewerPSProxy -ProxyUri "http://example.com/port" 30 | ``` 31 | 32 | Sets the proxy server to "". 33 | 34 | ### Example 2 35 | 36 | ```powershell 37 | PS /> Set-TeamViewerPSProxy -ProxyUri "http://10.0.0.1:3128" 38 | ``` 39 | 40 | Sets the proxy server to "". 41 | 42 | ## PARAMETERS 43 | 44 | ### -ProxyUri 45 | 46 | The Proxy server Uri. 47 | 48 | ```yaml 49 | Type: Uri 50 | Parameter Sets: (All) 51 | Aliases: 52 | 53 | Required: True 54 | Position: 0 55 | Default value: None 56 | Accept pipeline input: False 57 | Accept wildcard characters: False 58 | ``` 59 | 60 | ## INPUTS 61 | 62 | ### None 63 | 64 | ## OUTPUTS 65 | 66 | ## NOTES 67 | 68 | ## RELATED LINKS 69 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerRoleByUser.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerRoleByUser { 2 | param( 3 | [Parameter(Mandatory = $true)] 4 | [securestring] 5 | $ApiToken, 6 | 7 | [Parameter(Mandatory = $true)] 8 | [ValidateScript({ $_ | Resolve-TeamViewerUserId })] 9 | [Alias('UsersId')] 10 | [Alias('Id')] 11 | [string] 12 | $UserId 13 | ) 14 | 15 | begin { 16 | $copyUri = "$(Get-TeamViewerApiUri)/users/$userId/userroles" 17 | $parameters = $null 18 | $list = @() 19 | } 20 | process { 21 | $resourceUri = $copyUri 22 | do { 23 | $response = Invoke-TeamViewerRestMethod ` 24 | -ApiToken $ApiToken ` 25 | -Uri $resourceUri ` 26 | -Method Get ` 27 | -Body $parameters ` 28 | -WriteErrorTo $PSCmdlet ` 29 | -ErrorAction Stop 30 | 31 | if ($response.assignedRoleIds -and $response.assignedRoleIds.Count -gt 0) { 32 | $list += $response.assignedRoleIds 33 | } 34 | if ($response.nextPaginationToken) { 35 | $resourceUri = $copyUri + '?paginationToken=' + $response.nextPaginationToken 36 | } 37 | } while ($response.nextPaginationToken) 38 | return $list 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Tests/Public/Get-TeamViewerRoleByUserGroup.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Get-TeamViewerRoleByUserGroup.ps1" 3 | 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 5 | ForEach-Object { . $_.FullName } 6 | 7 | Mock Get-TeamViewerApiUri { '//unit.test' } 8 | Mock Invoke-TeamViewerRestMethod { @{ 9 | assignedRoleId = 15 10 | } } 11 | 12 | $testApiToken = [securestring]@{} 13 | $null = $testApiToken 14 | $testGroupId = '113456' 15 | $null = $testGroupId 16 | } 17 | 18 | Describe 'Get-TeamViewerUserGroupByRole' { 19 | Context 'When retrieving role assignments' { 20 | It 'Should call the correct API endpoint' { 21 | Get-TeamViewerRoleByUserGroup -ApiToken $testApiToken -GroupId $testGroupId 22 | 23 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 24 | $ApiToken -eq $testApiToken -And ` 25 | $Uri -eq "//unit.test/usergroups/$testGroupId/userroles" -And ` 26 | $Method -eq 'Get' 27 | } 28 | } 29 | 30 | It 'Should return assigned groups' { 31 | $result = Get-TeamViewerRoleByUserGroup -ApiToken $testApiToken -GroupId $testGroupId 32 | $result | Should -HaveCount 1 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Cmdlets/Public/Add-TeamViewerManagedDevice.ps1: -------------------------------------------------------------------------------- 1 | function Add-TeamViewerManagedDevice { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerManagedDeviceId } )] 10 | [Alias("DeviceId")] 11 | [object] 12 | $Device, 13 | 14 | [Parameter(Mandatory = $true)] 15 | [ValidateScript( { $_ | Resolve-TeamViewerManagedGroupId } )] 16 | [Alias("GroupId")] 17 | [object] 18 | $Group 19 | ) 20 | 21 | $deviceId = $Device | Resolve-TeamViewerManagedDeviceId 22 | $groupId = $Group | Resolve-TeamViewerManagedGroupId 23 | $resourceUri = "$(Get-TeamViewerApiUri)/managed/groups/$groupId/devices" 24 | 25 | $body = @{ 26 | id = $deviceId 27 | } 28 | 29 | if ($PSCmdlet.ShouldProcess($deviceId, "Add device to managed group")) { 30 | Invoke-TeamViewerRestMethod ` 31 | -ApiToken $ApiToken ` 32 | -Uri $resourceUri ` 33 | -Method Post ` 34 | -ContentType "application/json; charset=utf-8" ` 35 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 36 | -WriteErrorTo $PSCmdlet | ` 37 | Out-Null 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Tests/Public/Add-TeamViewerUserGroupToRole.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Add-TeamViewerUserGroupToRole.ps1" 3 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 4 | ForEach-Object { . $_.FullName } 5 | 6 | $testApiToken = [securestring]@{} 7 | $null = $testApiToken 8 | $testUserGroup = 1234 9 | $null = $testUserGroup 10 | $testRoleId = '9b465ea2-2f75-4101-a057-58a81ed0e57b' 11 | $null = $testRoleId 12 | Mock Get-TeamViewerApiUri { '//unit.test' } 13 | $mockArgs = @{} 14 | Mock Invoke-TeamViewerRestMethod { $mockArgs.Body = $Body 15 | @{ 16 | RoleId = $testRoleId 17 | UserGroupId = $testUserGroup 18 | } 19 | } 20 | } 21 | Describe 'Add-TeamViewerUserGroupToRole' { 22 | It 'Should call the correct API endpoint' { 23 | Add-TeamViewerUserGroupToRole -ApiToken $testApiToken -RoleId $testRoleId -UserGroup $testUserGroup 24 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 25 | $ApiToken -eq $testApiToken -And ` 26 | $Uri -eq '//unit.test/userroles/assign/usergroup' -And ` 27 | $Method -eq 'Post' 28 | } 29 | } 30 | 31 | # It 'Should return a Role/UserGroup object' { 32 | #Request doesn't return a response body 33 | # } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Docs/Help/Get-TeamViewerService.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Get-TeamViewerService.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-TeamViewerService 9 | 10 | ## SYNOPSIS 11 | 12 | Return the current state of the TeamViewer service. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Get-TeamViewerService [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Returns the current state of the TeamViewer service. 23 | This is platform dependent. 24 | 25 | On Windows platforms, the command will return the service object of the 26 | TeamViewer service. 27 | 28 | On Linux platforms, the command will output the current state (running, stopped, 29 | etc.) of the TeamViewer service. 30 | 31 | ## EXAMPLES 32 | 33 | ### Example 1 34 | 35 | ```powershell 36 | PS C:\> Get-TeamViewerService 37 | ``` 38 | 39 | ## PARAMETERS 40 | 41 | ### CommonParameters 42 | 43 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 44 | 45 | ## INPUTS 46 | 47 | ### None 48 | 49 | ## OUTPUTS 50 | 51 | ## NOTES 52 | 53 | ## RELATED LINKS 54 | -------------------------------------------------------------------------------- /Tests/Public/New-TeamViewerPolicy.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\New-TeamViewerPolicy.ps1" 3 | 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 5 | ForEach-Object { . $_.FullName } 6 | 7 | $testApiToken = [securestring]@{} 8 | $null = $testApiToken 9 | $mockArgs = @{} 10 | 11 | Mock Get-TeamViewerApiUri { '//unit.test' } 12 | Mock Invoke-TeamViewerRestMethod { $mockArgs.Body = $Body } 13 | } 14 | 15 | Describe 'New-TeamViewerPolicy' { 16 | It 'Should call the correct API endpoint' { 17 | New-TeamViewerPolicy -ApiToken $testApiToken -Name 'Unit Test Policy' 18 | 19 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 20 | $ApiToken -eq $testApiToken -And ` 21 | $Uri -eq '//unit.test/teamviewerpolicies' -And ` 22 | $Method -eq 'Post' } 23 | } 24 | 25 | It 'Should include the given name in the request' { 26 | New-TeamViewerPolicy ` 27 | -ApiToken $testApiToken ` 28 | -Name 'Unit Test Policy' ` 29 | -DefaultPolicy 30 | 31 | $mockArgs.Body | Should -Not -BeNullOrEmpty 32 | $body = [System.Text.Encoding]::UTF8.GetString($mockArgs.Body) | ConvertFrom-Json 33 | $body.name | Should -Be 'Unit Test Policy' 34 | $body.default | Should -BeTrue 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Cmdlets/Public/Set-TeamViewerUserGroup.ps1: -------------------------------------------------------------------------------- 1 | function Set-TeamViewerUserGroup { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerUserGroupId } )] 10 | [Alias("UserGroupId")] 11 | [Alias("Id")] 12 | [object] 13 | $UserGroup, 14 | 15 | [Parameter(Mandatory = $true)] 16 | [Alias("UserGroupName")] 17 | [string] 18 | $Name 19 | ) 20 | Begin { 21 | $id = $UserGroup | Resolve-TeamViewerUserGroupId 22 | $resourceUri = "$(Get-TeamViewerApiUri)/usergroups/$id" 23 | $body = @{ name = $Name } 24 | } 25 | Process { 26 | if ($PSCmdlet.ShouldProcess($UserGroup.ToString(), "Change user group")) { 27 | $response = Invoke-TeamViewerRestMethod ` 28 | -ApiToken $ApiToken ` 29 | -Uri $resourceUri ` 30 | -Method Put ` 31 | -ContentType "application/json; charset=utf-8" ` 32 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 33 | -WriteErrorTo $PSCmdlet ` 34 | -ErrorAction Stop 35 | Write-Output ($response | ConvertTo-TeamViewerUserGroup) 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerConnectionReport.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerConnectionReport { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | process { 8 | $properties = @{ 9 | Id = $InputObject.id 10 | UserId = $InputObject.userid 11 | UserName = $InputObject.username 12 | DeviceId = $InputObject.deviceid 13 | DeviceName = $InputObject.devicename 14 | GroupId = $InputObject.groupid 15 | GroupName = $InputObject.groupname 16 | SupportSessionType = [TeamViewerConnectionReportSessionType]$InputObject.support_session_type 17 | StartDate = $InputObject.start_date | ConvertTo-DateTime 18 | EndDate = $InputObject.end_date | ConvertTo-DateTime 19 | SessionCode = $InputObject.session_code 20 | Fee = $InputObject.fee 21 | BillingState = $InputObject.billing_state 22 | Currency = $InputObject.currency 23 | Notes = $InputObject.notes 24 | } 25 | 26 | $result = New-Object -TypeName PSObject -Property $properties 27 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.ConnectionReport') 28 | Write-Output $result 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Cmdlets/Private/Resolve-CustomizationErrorCode.ps1: -------------------------------------------------------------------------------- 1 | function Resolve-CustomizationErrorCode { 2 | param( 3 | [Parameter(ValueFromPipeline = $true, Mandatory = $true)] 4 | [object] 5 | $exitCode 6 | ) 7 | Begin { 8 | $exitCodeMessages = @{ 9 | 0 = 'Operation successful' 10 | 1 = 'Invalid command line arguments' 11 | 500 = 'An internal error occurred. See TeamViewer log files for more details!' 12 | 501 = 'The current user was denied access' 13 | 502 = 'The download of the custom configuration timed out' 14 | 503 = 'Invalid Module' 15 | 504 = 'Restart of the GUI failed' 16 | 505 = 'Custom configuration failed. See the TeamViewer log files for more details and check if the custom configuration id is still valid.' 17 | 506 = 'Removal of custom configuration failed. See the TeamViewer log files for more details!' 18 | } 19 | } 20 | Process { 21 | if ($exitCode) { 22 | if ($exitCodeMessages.ContainsKey($exitCode)) { 23 | Write-Output $exitCodeMessages[$exitCode] 24 | } 25 | else { 26 | Write-Output "Unexpected error code: $exitCode. Check TeamViewer documentation!" 27 | } 28 | } 29 | elseif ($exitCode -eq 0) { 30 | Write-Output $exitCodeMessages[$exitCode] 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerPolicyFromManagedGroup.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamviewerPolicyFromManagedGroup { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerManagedGroupId } )] 10 | [Alias('GroupId')] 11 | [object] 12 | $Group, 13 | 14 | [Parameter(Mandatory = $true)] 15 | [PolicyType] 16 | $PolicyType 17 | ) 18 | Begin { 19 | $body = @{ 20 | 'policy_type' = [int]$PolicyType 21 | } 22 | } 23 | Process { 24 | $groupId = $Group | Resolve-TeamViewerManagedGroupId 25 | $resourceUri = "$(Get-TeamViewerApiUri)/managed/groups/$groupId/policy/remove" 26 | 27 | if ($PSCmdlet.ShouldProcess($Group.ToString(), 'Change managed group entry')) { 28 | Invoke-TeamViewerRestMethod ` 29 | -ApiToken $ApiToken ` 30 | -Uri $resourceUri ` 31 | -Method Put ` 32 | -ContentType 'application/json; charset=utf-8' ` 33 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 34 | -WriteErrorTo $PSCmdlet ` 35 | -ErrorAction Stop | ` 36 | Out-Null 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerLogFilePath.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerLogFilePath { 2 | param( 3 | [switch] 4 | $OpenFile 5 | ) 6 | 7 | if (Test-TeamViewerInstallation) { 8 | if (Get-OperatingSystem -eq 'Windows') { 9 | $SearchDirectories = Get-TSCSearchDirectory 10 | $LogFiles = New-Object System.Collections.ArrayList 11 | foreach ($Name in $SearchDirectories.Keys) { 12 | $SearchDirectory = $SearchDirectories[$Name] 13 | foreach ($Folder in $SearchDirectory) { 14 | if (Test-Path -Path $Folder) { 15 | $files = Get-ChildItem -Path $Folder -File -Recurse 16 | foreach ($file in $files) { 17 | if ($file.Name.EndsWith('.log')) { 18 | $LogFiles.add($file.FullName) | Out-Null 19 | } 20 | } 21 | } 22 | } 23 | } 24 | 25 | if ($OpenFile) { 26 | $LogFile = $host.ui.PromptForChoice('Select file', 'Choose file:', ` 27 | @($LogFiles), 0) 28 | Invoke-Item -Path $LogFiles[$LogFile] 29 | } 30 | else { 31 | return $LogFiles 32 | } 33 | } 34 | } 35 | else { 36 | Write-Error 'TeamViewer is not installed.' 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Cmdlets/Public/New-TeamViewerContact.ps1: -------------------------------------------------------------------------------- 1 | function New-TeamViewerContact { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [Alias('EmailAddress')] 10 | [string] 11 | $Email, 12 | 13 | [Parameter(Mandatory = $true)] 14 | [ValidateScript( { $_ | Resolve-TeamViewerGroupId } )] 15 | [Alias("GroupId")] 16 | [object] 17 | $Group, 18 | 19 | [Parameter()] 20 | [switch] 21 | $Invite 22 | ) 23 | 24 | $body = @{ 25 | email = $Email 26 | groupid = $Group | Resolve-TeamViewerGroupId 27 | } 28 | if ($Invite) { 29 | $body['invite'] = $true 30 | } 31 | 32 | $resourceUri = "$(Get-TeamViewerApiUri)/contacts" 33 | if ($PSCmdlet.ShouldProcess($Email, "Create contact")) { 34 | $response = Invoke-TeamViewerRestMethod ` 35 | -ApiToken $ApiToken ` 36 | -Uri $resourceUri ` 37 | -Method Post ` 38 | -ContentType "application/json; charset=utf-8" ` 39 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 40 | -WriteErrorTo $PSCmdlet ` 41 | -ErrorAction Stop 42 | 43 | $result = ($response | ConvertTo-TeamViewerContact) 44 | Write-Output $result 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Cmdlets/Public/New-TeamViewerRole.ps1: -------------------------------------------------------------------------------- 1 | 2 | function New-TeamViewerRole { 3 | [CmdletBinding(SupportsShouldProcess = $true)] 4 | param( 5 | [Parameter(Mandatory = $true )] 6 | [securestring] 7 | $ApiToken, 8 | 9 | [Parameter(Mandatory = $true)] 10 | [Alias('RoleName')] 11 | [string] 12 | $Name, 13 | 14 | [Parameter(Mandatory = $false)] 15 | [AllowEmptyCollection()] 16 | [object[]] 17 | $Permissions 18 | ) 19 | Begin { 20 | $resourceUri = "$(Get-TeamViewerApiUri)/userroles" 21 | $body = @{ 22 | Name = $Name 23 | Permissions = @() 24 | } 25 | 26 | if ($Permissions) { 27 | $body.Permissions = @($Permissions) 28 | } 29 | } 30 | 31 | Process { 32 | if ($PSCmdlet.ShouldProcess($Name, 'Create Role')) { 33 | $response = Invoke-TeamViewerRestMethod ` 34 | -ApiToken $ApiToken ` 35 | -Uri $resourceUri ` 36 | -Method Post ` 37 | -ContentType 'application/json; charset=utf-8' ` 38 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 39 | -WriteErrorTo $PSCmdlet ` 40 | -ErrorAction Stop 41 | 42 | $result = ($response.Role | ConvertTo-TeamViewerRole) 43 | Write-Output $result 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerPolicyFromManagedDevice.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamviewerPolicyFromManagedDevice { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerManagedDeviceId } )] 10 | [Alias("DeviceId")] 11 | [object] 12 | $Device, 13 | 14 | [Parameter(Mandatory = $true)] 15 | [PolicyType] 16 | $PolicyType 17 | ) 18 | Begin { 19 | $body = @{ 20 | 'policy_type' = [int]$PolicyType 21 | } 22 | } 23 | Process { 24 | $deviceId = $Device | Resolve-TeamViewerManagedDeviceId 25 | $resourceUri = "$(Get-TeamViewerApiUri)/managed/devices/$deviceId/policy/remove" 26 | 27 | if ($PSCmdlet.ShouldProcess($Device.ToString(), "Change managed device entry")) { 28 | Invoke-TeamViewerRestMethod ` 29 | -ApiToken $ApiToken ` 30 | -Uri $resourceUri ` 31 | -Method Put ` 32 | -ContentType "application/json; charset=utf-8" ` 33 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 34 | -WriteErrorTo $PSCmdlet ` 35 | -ErrorAction Stop | ` 36 | Out-Null 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Tests/Private/Test-PublicFunctions.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | $Script:Module_RootPath = (Resolve-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath '..\..')) 3 | $Script:Module_FilePath = (Get-ChildItem -Path (Join-Path -Path $Module_RootPath -ChildPath 'Cmdlets') -Filter '*.psm1' -File).FullName 4 | $Script:Module_Name = (Split-Path -Path $Module_FilePath -Leaf).Replace('.psm1', '') 5 | $Script:PublicFuncFiles = (Get-ChildItem -Path (Join-Path -Path $Module_RootPath -ChildPath 'Cmdlets\Public') -Filter '*.ps1' -File | Select-Object BaseName) 6 | $Script:TestFilesDir = Join-Path -Path $Module_RootPath -ChildPath 'Tests\Public' 7 | $Script:HelpFilesDir = Join-Path -Path $Module_RootPath -ChildPath 'Docs\Help' 8 | } 9 | 10 | Describe 'Public Function File Checks' { 11 | Context 'Comparing directories' { 12 | It 'Function has a corresponding test file' { 13 | foreach ($funcName in $PublicFuncFiles.BaseName ) { 14 | $testFilePath = Join-Path -Path $TestFilesDir -ChildPath "$funcName.Tests.ps1" 15 | Test-Path $testFilePath | Should -Be $true 16 | } 17 | } 18 | } 19 | 20 | It 'Function has a corresponding help file' { 21 | foreach ($funcName in $PublicFuncFiles.BaseName) { 22 | $helpFilePath = Join-Path -Path $HelpFilesDir -ChildPath "$funcName.md" 23 | Test-Path $helpFilePath | Should -Be $true 24 | } 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /Tests/Public/Get-TeamViewerAccount.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Get-TeamViewerAccount.ps1" 3 | 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 5 | ForEach-Object { . $_.FullName } 6 | 7 | $testApiToken = [securestring]@{} 8 | $null = $testApiToken 9 | 10 | Mock Get-TeamViewerApiUri { '//unit.test' } 11 | Mock Invoke-TeamViewerRestMethod { 12 | @{ 13 | name = 'Unit Test' 14 | email = 'unit@example.test' 15 | userid = 'u1234' 16 | company_name = 'ACME Corp' 17 | email_validated = $true 18 | email_language = 'de' 19 | } 20 | } 21 | } 22 | 23 | Describe 'Get-TeamViewerAccount' { 24 | It 'Should call the correct API endpoint' { 25 | Get-TeamViewerAccount -ApiToken $testApiToken 26 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 27 | $ApiToken -eq $testApiToken -And ` 28 | $Uri -eq "//unit.test/account" -And ` 29 | $Method -eq 'Get' } 30 | } 31 | 32 | It 'Should return Account object' { 33 | $result = Get-TeamViewerAccount -ApiToken $testApiToken 34 | $result | Should -Not -BeNullOrEmpty 35 | $result.PSObject.TypeNames | Should -Contain 'TeamViewerPS.Account' 36 | $result.name | Should -Be 'Unit Test' 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerManager.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerManager { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject, 6 | 7 | [Parameter(Mandatory = $true, ParameterSetName = "GroupManager")] 8 | [guid] 9 | $GroupId, 10 | 11 | [Parameter(Mandatory = $true, ParameterSetName = "DeviceManager")] 12 | [guid] 13 | $DeviceId 14 | ) 15 | process { 16 | $properties = @{ 17 | Id = [guid]$InputObject.id 18 | ManagerType = $InputObject.type 19 | Name = $InputObject.name 20 | Permissions = $InputObject.permissions 21 | } 22 | 23 | switch ($InputObject.type) { 24 | 'account' { 25 | $properties.AccountId = $InputObject.accountId 26 | } 27 | 'company' { 28 | $properties.CompanyId = $InputObject.companyId 29 | } 30 | } 31 | 32 | switch ($PsCmdlet.ParameterSetName) { 33 | 'GroupManager' { 34 | $properties.GroupId = $GroupId 35 | } 36 | 'DeviceManager' { 37 | $properties.DeviceId = $DeviceId 38 | } 39 | } 40 | 41 | $result = New-Object -TypeName PSObject -Property $properties 42 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.Manager') 43 | Write-Output $result 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Tests/Public/Get-TeamViewerLogFilePath.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Get-TeamViewerLogFilePath.ps1" 3 | . "$PSScriptRoot\..\..\Cmdlets\Public\Test-TeamViewerInstallation.ps1" 4 | . "$PSScriptRoot\..\..\Cmdlets\Public\Get-TeamViewerInstallationDirectory.ps1" 5 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 6 | ForEach-Object { . $_.FullName } 7 | 8 | Mock Get-TSCSearchDirectory { 9 | @{ 10 | 'TestFolder1' = @('C:\Logs\TestFolder1') 11 | 'TestFolder2' = @('C:\Logs\TestFolder2') 12 | } 13 | } 14 | Mock Test-Path { $true } 15 | Mock Get-ChildItem { 16 | [PSCustomObject]@{ Name = 'file1.log'; FullName = 'C:\Logs\TestFolder1\file1.log' }, 17 | [PSCustomObject]@{ Name = 'file2.log'; FullName = 'C:\Logs\TestFolder2\file2.log' } 18 | } 19 | 20 | } 21 | 22 | Describe 'Get-TeamViewerLogFilePath function' { 23 | Context 'When TeamViewer is not installed' { 24 | BeforeAll { 25 | Mock Test-TeamViewerInstallation { return $false } 26 | Mock Write-Error { return } 27 | } 28 | 29 | It 'Should write an error message' { 30 | Mock -CommandName 'Write-Error' -MockWith { $null } 31 | Get-TeamViewerLogFilePath 32 | Assert-MockCalled -CommandName 'Write-Error' -Exactly -Times 1 33 | } 34 | } 35 | } 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Tests/Public/Get-TeamViewerUserByRole.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Get-TeamViewerUserByRole.ps1" 3 | 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 5 | ForEach-Object { . $_.FullName } 6 | 7 | Mock Get-TeamViewerApiUri { '//unit.test' } 8 | $Assigned = @('u201', 'u202') 9 | Mock Invoke-TeamViewerRestMethod { @{ 10 | ContinuationToken = $null 11 | AssignedToUsers = $Assigned 12 | } } 13 | 14 | $testApiToken = [securestring]@{} 15 | $null = $testApiToken 16 | $testRoleId = '72abbedc-9853-4fc8-9d28-fa35e207b048' 17 | $null = $testRoleId 18 | } 19 | 20 | Describe 'Get-TeamViewerUserByRole' { 21 | Context 'When retrieving role assignments' { 22 | It 'Should call the correct API endpoint' { 23 | Get-TeamViewerUserByRole -ApiToken $testApiToken -RoleId $testRoleId 24 | 25 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 26 | $ApiToken -eq $testApiToken -And ` 27 | $Uri -eq "//unit.test/userroles/assignments/account?userRoleId=$testRoleId" -And ` 28 | $Method -eq 'Get' 29 | } 30 | } 31 | 32 | It 'Should return assigned users' { 33 | $result = Get-TeamViewerUserByRole -ApiToken $testApiToken -RoleId $testRoleId 34 | $result | Should -HaveCount 2 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Tests/Public/Get-TeamViewerUserGroupByRole.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Get-TeamViewerUserGroupByRole.ps1" 3 | 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 5 | ForEach-Object { . $_.FullName } 6 | 7 | Mock Get-TeamViewerApiUri { '//unit.test' } 8 | $Assigned = @('1001', '1002') 9 | Mock Invoke-TeamViewerRestMethod { @{ 10 | ContinuationToken = $null 11 | AssignedToGroups = $Assigned 12 | } } 13 | 14 | $testApiToken = [securestring]@{} 15 | $null = $testApiToken 16 | $testRoleId = '72abbedc-9853-4fc8-9d28-fa35e207b048' 17 | $null = $testRoleId 18 | } 19 | 20 | Describe 'Get-TeamViewerUserGroupByRole' { 21 | Context 'When retrieving role assignments' { 22 | It 'Should call the correct API endpoint' { 23 | Get-TeamViewerUserGroupByRole -ApiToken $testApiToken -RoleId $testRoleId 24 | 25 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 26 | $ApiToken -eq $testApiToken -And ` 27 | $Uri -eq "//unit.test/userroles/assignments/usergroups?userRoleId=$testRoleId" -And ` 28 | $Method -eq 'Get' 29 | } 30 | } 31 | 32 | It 'Should return assigned groups' { 33 | $result = Get-TeamViewerUserGroupByRole -ApiToken $testApiToken -RoleId $testRoleId 34 | $result | Should -HaveCount 2 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Docs/Help/Invoke-TeamViewerPing.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Invoke-TeamViewerPing.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Invoke-TeamViewerPing 9 | 10 | ## SYNOPSIS 11 | 12 | Test the given TeamViewer API access token to be valid. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Invoke-TeamViewerPing [-ApiToken] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | This command tests the availability of the TeamViewer Web API and the validity 23 | of the given API access token. 24 | 25 | ## EXAMPLES 26 | 27 | ### Example 1 28 | 29 | ```powershell 30 | PS /> Invoke-TeamViewerPing 31 | ``` 32 | 33 | ## PARAMETERS 34 | 35 | ### -ApiToken 36 | 37 | The TeamViewer API access token. 38 | 39 | ```yaml 40 | Type: SecureString 41 | Parameter Sets: (All) 42 | Aliases: 43 | 44 | Required: True 45 | Position: 0 46 | Default value: None 47 | Accept pipeline input: False 48 | Accept wildcard characters: False 49 | ``` 50 | 51 | ### CommonParameters 52 | 53 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 54 | 55 | ## INPUTS 56 | 57 | ### None 58 | 59 | ## OUTPUTS 60 | 61 | ## NOTES 62 | 63 | ## RELATED LINKS 64 | -------------------------------------------------------------------------------- /Tests/Public/Remove-TeamViewerRole.Tests.ps1: -------------------------------------------------------------------------------- 1 | 2 | BeforeAll { 3 | . "$PSScriptRoot\..\..\Cmdlets\Public\Remove-TeamViewerRole.ps1" 4 | 5 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 6 | ForEach-Object { . $_.FullName } 7 | 8 | $testApiToken = [securestring]@{} 9 | $null = $testApiToken 10 | $testRoleId = '2bcf19dc-d5a9-4d25-952e-7cbb21762c9a' 11 | $null = $testRoleId 12 | 13 | Mock Get-TeamViewerApiUri { '//unit.test' } 14 | Mock Invoke-TeamViewerRestMethod {} 15 | } 16 | Describe 'Remove-TeamViewerRole' { 17 | It 'Should call the correct API endpoint' { 18 | Remove-TeamViewerRole -ApiToken $testApiToken -RoleId $testRoleId 19 | 20 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 21 | $ApiToken -eq $testApiToken -And ` 22 | $Uri -eq "//unit.test/userroles?userRoleId=$testRoleId" -And ` 23 | $Method -eq 'Delete' 24 | } 25 | } 26 | 27 | It 'Should handle domain object as input' { 28 | $testRole = @{Id = $testRoleId; Name = 'test user role' } | ConvertTo-TeamViewerRole 29 | Remove-TeamViewerRole -ApiToken $testApiToken -RoleId $testRole.RoleID 30 | 31 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 32 | $ApiToken -eq $testApiToken -And ` 33 | $Uri -eq "//unit.test/userroles?userRoleId=$testRoleId" -And ` 34 | $Method -eq 'Delete' 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Cmdlets/Private/Resolve-AssignmentErrorCode.ps1: -------------------------------------------------------------------------------- 1 | function Resolve-AssignmentErrorCode { 2 | param( 3 | [Parameter(ValueFromPipeline = $true, Mandatory = $true)] 4 | [object] 5 | $exitCode 6 | ) 7 | Begin { 8 | $exitCodeMessages = @{ 9 | 0 = 'Operation successful' 10 | 1 = 'Misspelled or used a wrong command' 11 | 2 = 'Signature verification error' 12 | 3 = 'TeamViewer is not installed' 13 | 4 = 'The assignment configuration could not be verified against the TeamViewer Cloud.Try again later.' 14 | 400 = 'Invalid assignment ID' 15 | 401 = 'TeamViewer service not running' 16 | 402 = 'Service Incompatible Version' 17 | 403 = 'Check your internet connection' 18 | 404 = 'Another assignment process running' 19 | 405 = 'Timeout' 20 | 406 = 'Failed due to unknown reasons' 21 | 407 = 'Access denied. Ensure local administrator rights' 22 | 408 = 'Denied by policy' 23 | } 24 | } 25 | Process { 26 | if ($exitCode) { 27 | if ($exitCodeMessages.ContainsKey($exitCode)) { 28 | Write-Output $exitCodeMessages[$exitCode] 29 | } 30 | else { 31 | Write-Output "Unexpected error code: $exitCode. Check TeamViewer documentation!" 32 | } 33 | } 34 | elseif ($exitCode -eq 0) { 35 | Write-Output $exitCodeMessages[$exitCode] 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerUserGroup.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerUserGroup { 2 | param( 3 | [Parameter(Mandatory = $true)] 4 | [securestring] 5 | $ApiToken, 6 | 7 | [Parameter()] 8 | [ValidateScript( { $_ | Resolve-TeamViewerUserGroupId } )] 9 | [Alias("UserGroupId")] 10 | [Alias("Id")] 11 | [object] 12 | $UserGroup 13 | ) 14 | 15 | Begin { 16 | $resourceUri = "$(Get-TeamViewerApiUri)/usergroups" 17 | $parameters = @{ } 18 | $isListOperation = $true 19 | 20 | if ($UserGroup) { 21 | $GroupId = $UserGroup | Resolve-TeamViewerUserGroupId 22 | $resourceUri += "/$GroupId" 23 | $parameters = $null 24 | $isListOperation = $false 25 | } 26 | } 27 | 28 | Process { 29 | do { 30 | $response = Invoke-TeamViewerRestMethod ` 31 | -ApiToken $ApiToken ` 32 | -Uri $resourceUri ` 33 | -Method Get ` 34 | -Body $parameters ` 35 | -WriteErrorTo $PSCmdlet ` 36 | -ErrorAction Stop 37 | if ($UserGroup) { 38 | Write-Output ($response | ConvertTo-TeamViewerUserGroup) 39 | } 40 | else { 41 | $parameters.paginationToken = $response.nextPaginationToken 42 | Write-Output ($response.resources | ConvertTo-TeamViewerUserGroup) 43 | } 44 | } while ($isListOperation -And $parameters.paginationToken) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Cmdlets/Private/ConvertTo-TeamViewerDevice.ps1: -------------------------------------------------------------------------------- 1 | function ConvertTo-TeamViewerDevice { 2 | param( 3 | [Parameter(ValueFromPipeline)] 4 | [PSObject] 5 | $InputObject 6 | ) 7 | process { 8 | $remoteControlId = $InputObject.remotecontrol_id | ` 9 | Select-String -Pattern 'r(\d+)' | ` 10 | ForEach-Object { $_.Matches.Groups[1].Value } 11 | $properties = @{ 12 | Id = $InputObject.device_id 13 | TeamViewerId = $remoteControlId 14 | GroupId = $InputObject.groupid 15 | Name = $InputObject.alias 16 | Description = $InputObject.description 17 | OnlineState = $InputObject.online_state 18 | IsAssignedToCurrentAccount = $InputObject.assigned_to 19 | SupportedFeatures = $InputObject.supported_features 20 | } 21 | if ($InputObject.policy_id) { 22 | $properties['PolicyId'] = $InputObject.policy_id 23 | } 24 | if ($InputObject.last_seen) { 25 | $properties['LastSeenAt'] = [datetime]($InputObject.last_seen) 26 | } 27 | $result = New-Object -TypeName PSObject -Property $properties 28 | $result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.Device') 29 | $result | Add-Member -MemberType ScriptMethod -Name "ToString" -Force -Value { 30 | Write-Output "$($this.Name)" 31 | } 32 | Write-Output $result 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Tests/Public/Remove-TeamViewerUserGroup.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Remove-TeamViewerUserGroup.ps1" 3 | 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 5 | ForEach-Object { . $_.FullName } 6 | 7 | $testApiToken = [securestring]@{} 8 | $null = $testApiToken 9 | $testUserGroupId = 1001 10 | $null = $testUserGroupId 11 | 12 | Mock Get-TeamViewerApiUri { '//unit.test' } 13 | Mock Invoke-TeamViewerRestMethod {} 14 | } 15 | 16 | Describe 'Remove-TeamViewerUserGroup' { 17 | 18 | It 'Should call the correct API endpoint' { 19 | Remove-TeamViewerUserGroup -ApiToken $testApiToken -UserGroup $testUserGroupId 20 | 21 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 22 | $ApiToken -eq $testApiToken -And ` 23 | $Uri -eq "//unit.test/usergroups/$testUserGroupId" -And ` 24 | $Method -eq 'Delete' 25 | } 26 | } 27 | 28 | It 'Should handle domain object as input' { 29 | $testUserGroup = @{Id = $testUserGroupId; Name = 'test user group' } | ConvertTo-TeamViewerUserGroup 30 | Remove-TeamViewerUserGroup -ApiToken $testApiToken -UserGroup $testUserGroup 31 | 32 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 33 | $ApiToken -eq $testApiToken -And ` 34 | $Uri -eq "//unit.test/usergroups/$testUserGroupId" -And ` 35 | $Method -eq 'Delete' 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Cmdlets/Public/Add-TeamViewerUserGroupToRole.ps1: -------------------------------------------------------------------------------- 1 | function Add-TeamViewerUserGroupToRole { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerRoleId } )] 10 | [Alias('RoleId')] 11 | [object] 12 | $Role, 13 | 14 | [Parameter(Mandatory = $true)] 15 | [ValidateScript( { $_ | Resolve-TeamViewerUserGroupId } )] 16 | [Alias('UserGroupId')] 17 | [Alias('Id')] 18 | [object] 19 | $UserGroup 20 | ) 21 | 22 | Begin { 23 | $RoleId = $Role | Resolve-TeamViewerRoleId 24 | $null = $ApiToken 25 | $resourceUri = "$(Get-TeamViewerApiUri)/userroles/assign/usergroup" 26 | $body = @{ 27 | UserRoleId = $RoleId 28 | UserGroupId = $UserGroup 29 | 30 | } 31 | } 32 | 33 | 34 | Process { 35 | if ($PSCmdlet.ShouldProcess($UserGroup, 'Assign Role to User Group')) { 36 | $result = Invoke-TeamViewerRestMethod ` 37 | -ApiToken $ApiToken ` 38 | -Uri $resourceUri ` 39 | -Method Post ` 40 | -ContentType 'application/json; charset=utf-8' ` 41 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 42 | -WriteErrorTo $PSCmdlet ` 43 | -ErrorAction Stop 44 | Write-Output ($result) 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Cmdlets/Public/Add-TeamViewerCustomization.ps1: -------------------------------------------------------------------------------- 1 | Function Add-TeamViewerCustomization { 2 | [CmdletBinding()] 3 | param ( 4 | [Parameter(Mandatory = $true, ParameterSetName = 'ById')] 5 | [object] 6 | $Id, 7 | 8 | [Parameter(Mandatory = $true, ParameterSetName = 'ByPath')] 9 | [object] 10 | $Path, 11 | 12 | [switch] 13 | $RestartGUI, 14 | 15 | [switch] 16 | $RemoveExisting 17 | ) 18 | 19 | if (Get-OperatingSystem -eq 'Windows') { 20 | if (Test-TeamViewerInstallation) { 21 | $installationDirectory = Get-TeamViewerInstallationDirectory 22 | $currentDirectory = Get-Location 23 | Set-Location $installationDirectory 24 | $cmd = 'customize' 25 | if ($Id) { 26 | $cmd += " --id $Id" 27 | } 28 | elseif ($Path) { 29 | $cmd += " --path $Path" 30 | } 31 | if ($RemoveExisting) { 32 | $cmd += ' --remove' 33 | } 34 | if ($RestartGUI) { 35 | $cmd += ' --restart-gui' 36 | } 37 | $process = Start-Process -FilePath TeamViewer.exe -ArgumentList $cmd -Wait -PassThru 38 | $process.ExitCode | Resolve-CustomizationErrorCode 39 | Set-Location $currentDirectory 40 | } 41 | else { 42 | Write-Error 'TeamViewer is not installed' 43 | } 44 | } 45 | else { 46 | Write-Error 'Customization is currently supported only on Windows.' 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Docs/Help/Get-TeamViewerAccount.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Get-TeamViewerAccount.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-TeamViewerAccount 9 | 10 | ## SYNOPSIS 11 | 12 | Retrieves account information of the TeamViewer account. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Get-TeamViewerAccount [-ApiToken] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Retrieves account information of the TeamViewer account associated with the 23 | TeamViewer API access token. 24 | 25 | ## EXAMPLES 26 | 27 | ### Example 1 28 | 29 | ```powershell 30 | PS /> $account = Get-TeamViewerAccount 31 | ``` 32 | 33 | Retrieve the account information and store the result in a variable. 34 | 35 | ## PARAMETERS 36 | 37 | ### -ApiToken 38 | 39 | The TeamViewer API access token. 40 | 41 | ```yaml 42 | Type: SecureString 43 | Parameter Sets: (All) 44 | Aliases: 45 | 46 | Required: True 47 | Position: 0 48 | Default value: None 49 | Accept pipeline input: False 50 | Accept wildcard characters: False 51 | ``` 52 | 53 | ### CommonParameters 54 | 55 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 56 | 57 | ## INPUTS 58 | 59 | ### None 60 | 61 | ## OUTPUTS 62 | 63 | ## NOTES 64 | 65 | ## RELATED LINKS 66 | -------------------------------------------------------------------------------- /Cmdlets/Private/Get-TeamViewerLinuxGlobalConfig.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerLinuxGlobalConfig { 2 | param( 3 | [Parameter()] 4 | [string] 5 | $Path = '/opt/teamviewer/config/global.conf', 6 | 7 | [Parameter()] 8 | [string] 9 | $Name 10 | ) 11 | $config = & sudo pwsh -command Get-Content $Path | ForEach-Object { 12 | if ($_ -Match '\[(?\w+)\s*\]\s+(?[\w\\]+)\s+=\s*(?.*)$') { 13 | $Matches.Remove(0) 14 | $entry = [pscustomobject]$Matches 15 | switch ($entry.EntryType) { 16 | 'strng' { 17 | $entry.EntryValue = $entry.EntryValue | ` 18 | Select-String -Pattern '"([^\"]*)"' -AllMatches | ` 19 | Select-Object -ExpandProperty Matches | ` 20 | ForEach-Object { $_.Groups[1].Value } 21 | } 22 | 'int32' { 23 | $entry.EntryValue = [int32]($entry.EntryValue) 24 | } 25 | 'int64' { 26 | #In some cases the EntryName DeviceManagement/TransitionNonces is set to entryvalue '0 0 0 0 0' of type int64 27 | if ($entry.EntryValue -notmatch '0 0 0 0 0') { 28 | $entry.EntryValue = [int64]($entry.EntryValue) 29 | } 30 | } 31 | } 32 | $entry 33 | } 34 | } 35 | 36 | if ($Name) { 37 | ($config | Where-Object { $_.EntryName -eq $Name }).EntryValue 38 | } 39 | else { 40 | $config 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/Public/Remove-TeamViewerUserGroupFromRole.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Remove-TeamViewerUserGroupFromRole.ps1" 3 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 4 | ForEach-Object { . $_.FullName } 5 | 6 | $testApiToken = [securestring]@{} 7 | $null = $testApiToken 8 | $testUserGroup = 1234 9 | $null = $testUserGroup 10 | 11 | 12 | Mock Get-TeamViewerApiUri { '//unit.test' } 13 | $mockArgs = @{} 14 | Mock Invoke-TeamViewerRestMethod { $mockArgs.Body = $Body 15 | @{ 16 | UserGroupId = $testUserGroup 17 | } 18 | } 19 | } 20 | Describe 'Remove-TeamViewerUserGroupFromRole' { 21 | 22 | It 'Should call the correct API endpoint' { 23 | Remove-TeamViewerUserGroupFromRole -ApiToken $testApiToken -UserGroup $testUserGroup 24 | 25 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 26 | $ApiToken -eq $testApiToken -And ` 27 | $Uri -eq '//unit.test/userroles/unassign/usergroup' -And ` 28 | $Method -eq 'Post' 29 | } 30 | } 31 | 32 | It 'Should unassign the given user group from the user role' { 33 | Remove-TeamViewerUserGroupFromRole ` 34 | -ApiToken $testApiToken ` 35 | -UserGroup $testUserGroup 36 | $mockArgs.Body | Should -Not -BeNullOrEmpty 37 | $body = [System.Text.Encoding]::UTF8.GetString($mockArgs.Body) | ConvertFrom-Json 38 | $body.UserGroupId | Should -HaveCount 1 39 | $body.UserGroupId | Should -Be $testUserGroup 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Cmdlets/Public/Set-TeamViewerRole.ps1: -------------------------------------------------------------------------------- 1 | 2 | function Set-TeamViewerRole { 3 | [CmdletBinding(SupportsShouldProcess = $true)] 4 | param( 5 | [Parameter(Mandatory = $true )] 6 | [securestring] 7 | $ApiToken, 8 | 9 | [Parameter(Mandatory = $true)] 10 | [Alias('RoleName')] 11 | [string] 12 | $Name, 13 | 14 | [Parameter(Mandatory = $false)] 15 | [AllowEmptyCollection()] 16 | [object[]] 17 | $Permissions, 18 | 19 | [Parameter(Mandatory = $true)] 20 | [ValidateScript( { $_ | Resolve-TeamViewerRoleId } )] 21 | [Alias('Role')] 22 | [object] 23 | $RoleId 24 | ) 25 | Begin { 26 | $resourceUri = "$(Get-TeamViewerApiUri)/userroles" 27 | $body = @{ 28 | Name = $Name 29 | Permissions = @() 30 | UserRoleId = $RoleId 31 | 32 | } 33 | if ($Permissions) { 34 | $body.Permissions = @($Permissions) 35 | } 36 | } 37 | Process { 38 | if ($PSCmdlet.ShouldProcess($Name, 'Update Role')) { 39 | $response = Invoke-TeamViewerRestMethod ` 40 | -ApiToken $ApiToken ` 41 | -Uri $resourceUri ` 42 | -Method Put ` 43 | -ContentType 'application/json; charset=utf-8' ` 44 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 45 | -WriteErrorTo $PSCmdlet ` 46 | -ErrorAction Stop 47 | 48 | $result = $response 49 | Write-Output $result 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /Cmdlets/Private/Add-Registry.ps1: -------------------------------------------------------------------------------- 1 | function Add-Registry { 2 | param ( 3 | [Microsoft.Win32.RegistryKey]$RegKey, 4 | [string]$Program 5 | ) 6 | 7 | #CustomObject including all information for each registry and sub keys 8 | $retRegKey = [PSCustomObject]@{ 9 | Program = $Program 10 | RegistryPath = $RegKey.Name 11 | Entries = @() 12 | } 13 | Write-Output "Collecting registry data $($retRegKey.RegistryPath)" 14 | foreach ($valueName in $RegKey.GetValueNames()) { 15 | $value = $RegKey.GetValue($valueName) 16 | $type, $value = Get-TypeAndValueOfRegistryValue -RegKey $RegKey -ValueName $valueName 17 | $blackList = @('BuddyLoginTokenAES', 'BuddyLoginTokenSecretAES', 'Certificate', 'CertificateKey', 'CertificateKeyProtected', 18 | 'MultiPwdMgmtPwdData', 'PermanentPassword', 'PK', 'SecurityPasswordAES', 'SK', 'SRPPasswordMachineIdentifier') 19 | foreach ($blackListValue in $blackList) { 20 | if ($valueName -eq $blackListValue) { 21 | $value = '___PRIVATE___' 22 | } 23 | } 24 | $entry = [PSCustomObject]@{ 25 | Name = $valueName 26 | Value = $value 27 | Type = $type 28 | } 29 | $retRegKey.Entries += $entry 30 | } 31 | 32 | foreach ($subKeyName in $RegKey.GetSubKeyNames()) { 33 | $subKey = $RegKey.OpenSubKey($subKeyName) 34 | Add-Registry -RegKey $subKey -Program $subKeyName 35 | } 36 | #Adding CustomObject to array declared in Get-RegistryPaths 37 | $AllTVRegistryData.Add($retRegKey) | Out-Null 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /Cmdlets/Private/Get-InstalledSoftware.ps1: -------------------------------------------------------------------------------- 1 | function Get-InstalledSoftware { 2 | param( 3 | [Parameter(ValueFromPipeline = $true)] 4 | [string] 5 | $OutputPath 6 | ) 7 | Begin { 8 | $regUninstall = @{ 9 | InstalledSoftware32 = 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall' 10 | InstalledSoftware64 = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall' 11 | } 12 | } 13 | Process { 14 | foreach ($Name in $regUninstall.keys) { 15 | $regKeys = $regUninstall[$Name] 16 | $regKey = Get-ItemProperty -Path "$regKeys\*" 17 | if ($null -ne $regKey) { 18 | $subKeys = $regKey.PSChildName 19 | if ($null -ne $subKeys) { 20 | $installedPrograms = @() 21 | foreach ($subKey in $subKeys) { 22 | $tmpSubkey = Get-ItemProperty -Path "$regKeys\$subKey" 23 | $programmName = $tmpSubkey.DisplayName 24 | $displayVersion = $tmpSubkey.DisplayVersion 25 | if ($null -ne $programmName) { 26 | $tmpSoftwareData = "$programmName | $displayVersion" 27 | $installedPrograms += $tmpSoftwareData 28 | } 29 | } 30 | } 31 | $installedPrograms | Sort-Object | Out-File -FilePath "$OutputPath\Data\$Name.txt" 32 | Write-Output "$Name collected and saved to $OutputPath\Data\$Name.txt" 33 | } 34 | } 35 | } 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /Docs/Help/Get-TeamViewerEffectivePermission.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Get-TeamViewerEffectivePermission.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-TeamViewerEffectivePermission 9 | 10 | ## SYNOPSIS 11 | 12 | Lists all effective permissions in a TeamViewer company. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Get-TeamViewerEffectivePermission [-ApiToken] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Lists all effective permissions in the TeamViewer company associated with the API access token. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS /> Get-TeamViewerEffectivePermission 30 | ``` 31 | 32 | Lists all effective permissions. 33 | 34 | ## PARAMETERS 35 | 36 | ### -ApiToken 37 | 38 | The TeamViewer API access token. 39 | 40 | ```yaml 41 | Type: SecureString 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 0 47 | Default value: None 48 | Accept pipeline input: False 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### CommonParameters 53 | 54 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 55 | 56 | ## INPUTS 57 | 58 | ### None 59 | 60 | ## OUTPUTS 61 | 62 | ### System.Object 63 | 64 | ## NOTES 65 | 66 | ## RELATED LINKS 67 | -------------------------------------------------------------------------------- /Docs/Help/Set-TeamViewerAPIUri.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Set-TeamViewerAPIUri.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Set-TeamViewerAPIUri 9 | 10 | ## SYNOPSIS 11 | 12 | Change uri of the TeamViewer web API for TeamViewerPS. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Set-TeamViewerAPIUri [-NewUri ] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Change uri of TeamViewer web API for TeamViewer internal testing purposes. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS /> Set-TeamViewerAPIUri -NewUri 'www.example.com' 30 | ``` 31 | 32 | Sets the uri of the web API to `www.example.com`. 33 | 34 | ### Example 2 35 | 36 | ```powershell 37 | PS /> Set-TeamViewerAPIUri -Default $true 38 | ``` 39 | 40 | Sets the WebAPI for TeamViewerPS to the default value. 41 | 42 | ## PARAMETERS 43 | 44 | ### -NewUri 45 | 46 | Sets a specific uri to the web API for TeamViewerPS. 47 | 48 | ```yaml 49 | Type: String 50 | Parameter Sets: None 51 | Aliases: None 52 | 53 | Required: False 54 | Position: Named 55 | Default value: None 56 | Accept pipeline input: False 57 | Accept wildcard characters: False 58 | ``` 59 | 60 | ### -Default 61 | 62 | Sets the web API for TeamViewerPS to the default value. 63 | 64 | ```yaml 65 | Type: Bool 66 | Parameter Sets: None 67 | Aliases: 68 | 69 | Required: False 70 | Position: Named 71 | Default value: None 72 | Accept pipeline input: False 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ## INPUTS 77 | 78 | ### None 79 | 80 | ## OUTPUTS 81 | 82 | ## NOTES 83 | 84 | ## RELATED LINKS 85 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 for the documentation about the tasks.json format 3 | "version": "2.0.0", 4 | "tasks": [ 5 | { 6 | "label": "Lint (via PSScriptAnalyzer)", 7 | "type": "shell", 8 | "command": "& Invoke-ScriptAnalyzer -Path \\\"${workspaceFolder}\\\" -Recurse -Settings \\\"${workspaceFolder}/Linters/PSScriptAnalyzer.psd1\\\"", 9 | "group": { 10 | "kind": "test", 11 | "isDefault": true 12 | } 13 | }, 14 | { 15 | "label": "Test (via Pester)", 16 | "type": "shell", 17 | "command": "& Invoke-Pester -Path \\\"${workspaceFolder}\\\"", 18 | "group": { 19 | "kind": "test", 20 | "isDefault": false 21 | } 22 | }, 23 | { 24 | "label": "Clean", 25 | "type": "shell", 26 | "command": "Invoke-Build -Task Clean", 27 | "problemMatcher": [] 28 | }, 29 | { 30 | "label": "Build", 31 | "type": "shell", 32 | "command": "Invoke-Build -Task Build", 33 | "group": { 34 | "kind": "build", 35 | "isDefault": true 36 | }, 37 | "problemMatcher": [] 38 | }, 39 | { 40 | "label": "Test", 41 | "type": "shell", 42 | "command": "Invoke-Build -Task Test", 43 | "group": { 44 | "kind": "test", 45 | "isDefault": true 46 | }, 47 | "problemMatcher": [] 48 | } 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /Docs/Help/Remove-TeamViewerPredefinedRole.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Remove-TeamViewerPredefinedRole.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Remove-TeamViewerPredefinedRole 9 | 10 | ## SYNOPSIS 11 | 12 | Sets the existing predefined role to a not predefined one. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Remove-TeamViewerPredefinedRole [-ApiToken] [-RoleId] [-WhatIf] [-Confirm] 18 | [] 19 | ``` 20 | 21 | ## DESCRIPTION 22 | 23 | Sets the existing predefined role to a not predefined one. The role is still available. 24 | The user assignments of this role are unaffected. 25 | 26 | ## EXAMPLES 27 | 28 | ### Example 1 29 | 30 | ```powershell 31 | PS /> Remove-TeamViewerPredefinedRole 32 | ``` 33 | 34 | Removes the predefined role flag from the role. 35 | 36 | ## PARAMETERS 37 | 38 | ### -ApiToken 39 | 40 | The TeamViewer API access token. 41 | 42 | ```yaml 43 | Type: SecureString 44 | Parameter Sets: (All) 45 | Aliases: 46 | 47 | Required: True 48 | Position: 0 49 | Default value: None 50 | Accept pipeline input: False 51 | Accept wildcard characters: False 52 | ``` 53 | 54 | ### CommonParameters 55 | 56 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 57 | 58 | ## INPUTS 59 | 60 | ### None 61 | 62 | ## OUTPUTS 63 | 64 | ## NOTES 65 | 66 | ## RELATED LINKS 67 | -------------------------------------------------------------------------------- /Cmdlets/Public/Publish-TeamViewerGroup.ps1: -------------------------------------------------------------------------------- 1 | function Publish-TeamViewerGroup { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerGroupId } )] 10 | [Alias("GroupId")] 11 | [object] 12 | $Group, 13 | 14 | [Parameter(Mandatory = $true)] 15 | [ValidateScript( { $_ | Resolve-TeamViewerUserId } )] 16 | [Alias("UserId")] 17 | [object[]] 18 | $User, 19 | 20 | [Parameter()] 21 | [ValidateSet("read", "readwrite")] 22 | $Permissions = "read" 23 | ) 24 | 25 | # Warning suppresion doesn't seem to work. 26 | # See https://github.com/PowerShell/PSScriptAnalyzer/issues/1472 27 | $null = $Permissions 28 | 29 | $groupId = $Group | Resolve-TeamViewerGroupId 30 | $userIds = $User | Resolve-TeamViewerUserId 31 | $resourceUri = "$(Get-TeamViewerApiUri)/groups/$groupId/share_group" 32 | $body = @{ 33 | users = @($userIds | ForEach-Object { @{ 34 | userid = $_ 35 | permissions = $Permissions 36 | } }) 37 | } 38 | 39 | if ($PSCmdlet.ShouldProcess($userids, "Add group share")) { 40 | Invoke-TeamViewerRestMethod ` 41 | -ApiToken $ApiToken ` 42 | -Uri $resourceUri ` 43 | -Method Post ` 44 | -ContentType "application/json; charset=utf-8" ` 45 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 46 | -WriteErrorTo $PSCmdlet | ` 47 | Out-Null 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Cmdlets/Public/Export-TeamViewerSystemInformation.ps1: -------------------------------------------------------------------------------- 1 | function Export-TeamViewerSystemInformation { 2 | param( 3 | [Parameter(ValueFromPipeline = $true)] 4 | [string] 5 | $TargetDirectory 6 | ) 7 | Process { 8 | if (Test-TeamViewerInstallation ) { 9 | if (Get-OperatingSystem -eq 'Windows') { 10 | $Temp = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), [System.Guid]::NewGuid().ToString()) 11 | $CurrentDirectory = Get-Location 12 | $Temp | Get-TSCDirectoryFile 13 | $Temp | Get-InstalledSoftware 14 | $Temp | Get-IpConfig 15 | $Temp | Get-MSInfo32 16 | $Temp | Get-HostFile 17 | $Temp | Get-NSLookUpData 18 | $Temp | Get-RouteTable 19 | $Temp | Get-RegistryPath 20 | $ClientID = Get-ClientId 21 | $ZipFileName = 'TV_SC_' + $ClientID + '_WINPS.zip' 22 | $ZipPath = Join-Path -Path "$Temp\Data" -ChildPath $ZipFileName 23 | Compress-Archive -Path $Temp\* -DestinationPath $ZipPath -Force 24 | if ($TargetDirectory -and (Test-Path $TargetDirectory)) { 25 | Copy-Item -Path $ZipPath -Destination $TargetDirectory -Force 26 | } 27 | else { 28 | Copy-Item -Path $ZipPath -Destination $CurrentDirectory -Force 29 | } 30 | } 31 | else { 32 | Write-Error 'Currently this functionality is supported only on Windows.' 33 | } 34 | } 35 | else { 36 | Write-Error 'TeamViewer is not installed.' 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerManager.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerManager { 2 | [CmdletBinding(DefaultParameterSetName = "ByDeviceId")] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true, ParameterSetName = "ByDeviceId")] 9 | [ValidateScript( { $_ | Resolve-TeamViewerManagedDeviceId } )] 10 | [Alias("DeviceId")] 11 | [object] 12 | $Device, 13 | 14 | [Parameter(Mandatory = $true, ParameterSetName = "ByGroupId")] 15 | [ValidateScript( { $_ | Resolve-TeamViewerManagedGroupId } )] 16 | [Alias("GroupId")] 17 | [object] 18 | $Group 19 | ) 20 | 21 | $resourceUri = $null 22 | switch ($PsCmdlet.ParameterSetName) { 23 | 'ByDeviceId' { 24 | $deviceId = $Device | Resolve-TeamViewerManagedDeviceId 25 | $resourceUri = "$(Get-TeamViewerApiUri)/managed/devices/$deviceId/managers" 26 | } 27 | 'ByGroupId' { 28 | $groupId = $Group | Resolve-TeamViewerManagedGroupId 29 | $resourceUri = "$(Get-TeamViewerApiUri)/managed/groups/$groupId/managers" 30 | } 31 | } 32 | 33 | $response = Invoke-TeamViewerRestMethod ` 34 | -ApiToken $ApiToken ` 35 | -Uri $resourceUri ` 36 | -Method Get ` 37 | -WriteErrorTo $PSCmdlet ` 38 | -ErrorAction Stop 39 | 40 | switch ($PsCmdlet.ParameterSetName) { 41 | 'ByDeviceId' { 42 | Write-Output ($response.resources | ConvertTo-TeamViewerManager -DeviceId $deviceId) 43 | } 44 | 'ByGroupId' { 45 | Write-Output ($response.resources | ConvertTo-TeamViewerManager -GroupId $groupId) 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Cmdlets/Private/Get-TSCDirectoryFile.ps1: -------------------------------------------------------------------------------- 1 | function Get-TSCDirectoryFile { 2 | param( 3 | [Parameter(ValueFromPipeline = $true)] 4 | [string] 5 | $OutputPath 6 | ) 7 | 8 | Process { 9 | $SearchDirectories = Get-TSCSearchDirectory 10 | $TempDirectory = New-Item -Path $OutputPath -Name 'Data' -ItemType Directory -Force 11 | $Endings = @('.log', 'tvinfo.ini', '.mdmp', 'Connections.txt', 'Connections_incoming.txt') 12 | $TmpLogFiles = @() 13 | foreach ($Name in $SearchDirectories.Keys) { 14 | $SearchDirectory = $SearchDirectories[$Name] 15 | foreach ($Folder in $SearchDirectory) { 16 | if (Test-Path -Path $Folder) { 17 | $TempSubdirectory = Join-Path -Path $TempDirectory -ChildPath $Name 18 | New-Item -Path $TempSubdirectory -ItemType Directory -Force | Out-Null 19 | $files = Get-ChildItem -Path $Folder -File -Recurse 20 | foreach ($file in $files) { 21 | foreach ($ending in $Endings) { 22 | if ($file.Name.EndsWith($ending)) { 23 | $tmpLogfilePath = Join-Path -Path $TempSubdirectory -ChildPath $file.Name 24 | Copy-Item -Path $file.FullName -Destination $tmpLogfilePath -Force 25 | $TmpLogFiles += $tmpLogfilePath 26 | Write-Output "Collected log file from $($file.FullName)" 27 | } 28 | } 29 | } 30 | } 31 | } 32 | } 33 | Write-Output 'Files from TeamViewer directories have been collected.' 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Docs/Help/Get-TeamViewerSsoDomain.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Get-TeamViewerSsoDomain.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-TeamViewerSsoDomain 9 | 10 | ## SYNOPSIS 11 | 12 | Get a list of TeamViewer SSO domains that are owned by the current account. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Get-TeamViewerSsoDomain [-ApiToken] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Get a list of TeamViewer SSO domain configurations that are owned by the 23 | account that is associated with the API access token. 24 | 25 | ## EXAMPLES 26 | 27 | ### Example 1 28 | 29 | ```powershell 30 | PS /> Get-TeamViewerSsoDomain 31 | ``` 32 | 33 | ## PARAMETERS 34 | 35 | ### -ApiToken 36 | 37 | The TeamViewer API access token. 38 | 39 | ```yaml 40 | Type: SecureString 41 | Parameter Sets: (All) 42 | Aliases: 43 | 44 | Required: True 45 | Position: 0 46 | Default value: None 47 | Accept pipeline input: False 48 | Accept wildcard characters: False 49 | ``` 50 | 51 | ### CommonParameters 52 | 53 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 54 | 55 | ## INPUTS 56 | 57 | ## OUTPUTS 58 | 59 | ## NOTES 60 | 61 | ## RELATED LINKS 62 | 63 | [Get-TeamViewerSsoExclusion](Get-TeamViewerSsoExclusion.md) 64 | 65 | [Add-TeamViewerSsoExclusion](Add-TeamViewerSsoExclusion.md) 66 | 67 | [Remove-TeamViewerSsoExclusion](Remove-TeamViewerSsoExclusion.md) 68 | -------------------------------------------------------------------------------- /Cmdlets/Public/Add-TeamViewerSsoInclusion.ps1: -------------------------------------------------------------------------------- 1 | function Add-TeamViewerSsoInclusion { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerSsoDomainId } )] 10 | [Alias("Domain")] 11 | [object] 12 | $DomainId, 13 | 14 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 15 | [string[]] 16 | $Email 17 | ) 18 | Begin { 19 | $id = $DomainId | Resolve-TeamViewerSsoDomainId 20 | $resourceUri = "$(Get-TeamViewerApiUri)/ssoDomain/$id/inclusion" 21 | $emailsToAdd = @() 22 | $null = $ApiToken 23 | 24 | function Invoke-RequestInternal { 25 | $body = @{ 26 | emails = @($emailsToAdd) 27 | } 28 | Invoke-TeamViewerRestMethod ` 29 | -ApiToken $ApiToken ` 30 | -Uri $resourceUri ` 31 | -Method Post ` 32 | -ContentType "application/json; charset=utf-8" ` 33 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 34 | -WriteErrorTo $PSCmdlet ` 35 | -ErrorAction Stop | ` 36 | Out-Null 37 | } 38 | } 39 | Process { 40 | if ($PSCmdlet.ShouldProcess($Email, "Add SSO inclusion")) { 41 | $emailsToAdd += $Email 42 | } 43 | if ($emailsToAdd.Length -eq 100) { 44 | Invoke-RequestInternal 45 | $emailsToAdd = @() 46 | } 47 | } 48 | End { 49 | if ($emailsToAdd.Length -gt 0) { 50 | Invoke-RequestInternal 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /Cmdlets/Public/Move-TeamViewerManagedDevice.ps1: -------------------------------------------------------------------------------- 1 | function Move-TeamViewerManagedDevice { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerManagedDeviceId } )] 10 | [Alias("DeviceId")] 11 | [object] 12 | $Device, 13 | 14 | [Parameter(Mandatory = $true)] 15 | [ValidateScript( { $_ | Resolve-TeamViewerManagedGroupId } )] 16 | [Alias("Source GroupId")] 17 | [object] 18 | $SourceGroup, 19 | 20 | [Parameter(Mandatory = $true)] 21 | [ValidateScript( { $_ | Resolve-TeamViewerManagedGroupId } )] 22 | [Alias("Target GroupId")] 23 | [object] 24 | $TargetGroup 25 | ) 26 | 27 | $deviceId = $Device | Resolve-TeamViewerManagedDeviceId 28 | $sourceGroupId = $SourceGroup | Resolve-TeamViewerManagedGroupId 29 | $targetGroupId = $TargetGroup | Resolve-TeamViewerManagedGroupId 30 | $resourceUri = "$(Get-TeamViewerApiUri)/managed/devices/$deviceId/groups" 31 | 32 | $body = @{ 33 | AddedChainIds = @($targetGroupId) 34 | RemovedChainIds = @($sourceGroupId) 35 | } 36 | 37 | if ($PSCmdlet.ShouldProcess($deviceId, "Move a device from one group to another")) { 38 | Invoke-TeamViewerRestMethod ` 39 | -ApiToken $ApiToken ` 40 | -Uri $resourceUri ` 41 | -Method Put ` 42 | -ContentType "application/json; charset=utf-8" ` 43 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 44 | -WriteErrorTo $PSCmdlet | ` 45 | Out-Null 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Cmdlets/Public/Get-TeamViewerGroup.ps1: -------------------------------------------------------------------------------- 1 | function Get-TeamViewerGroup { 2 | [CmdletBinding(DefaultParameterSetName = "FilteredList")] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(ParameterSetName = "ByGroupId")] 9 | [Alias("GroupId")] 10 | [string] 11 | $Id, 12 | 13 | [Parameter(ParameterSetName = "FilteredList")] 14 | [Alias("PartialName")] 15 | [string] 16 | $Name, 17 | 18 | [Parameter(ParameterSetName = "FilteredList")] 19 | [ValidateSet('OnlyShared', 'OnlyNotShared')] 20 | [string] 21 | $FilterShared 22 | ) 23 | 24 | $resourceUri = "$(Get-TeamViewerApiUri)/groups"; 25 | $parameters = @{ } 26 | 27 | switch ($PsCmdlet.ParameterSetName) { 28 | 'ByGroupId' { 29 | $resourceUri += "/$Id" 30 | $parameters = $null 31 | } 32 | 'FilteredList' { 33 | if ($Name) { 34 | $parameters['name'] = $Name 35 | } 36 | switch ($FilterShared) { 37 | 'OnlyShared' { $parameters['shared'] = $true } 38 | 'OnlyNotShared' { $parameters['shared'] = $false } 39 | } 40 | } 41 | } 42 | 43 | $response = Invoke-TeamViewerRestMethod ` 44 | -ApiToken $ApiToken ` 45 | -Uri $resourceUri ` 46 | -Method Get ` 47 | -Body $parameters ` 48 | -WriteErrorTo $PSCmdlet ` 49 | -ErrorAction Stop 50 | 51 | if ($PsCmdlet.ParameterSetName -Eq 'ByGroupId') { 52 | Write-Output ($response | ConvertTo-TeamViewerGroup) 53 | } 54 | else { 55 | Write-Output ($response.groups | ConvertTo-TeamViewerGroup) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Tests/Public/Remove-TeamViewerDevice.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Remove-TeamViewerDevice.ps1" 3 | 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 5 | ForEach-Object { . $_.FullName } 6 | 7 | $testApiToken = [securestring]@{} 8 | $null = $testApiToken 9 | 10 | Mock Get-TeamViewerApiUri { '//unit.test' } 11 | Mock Invoke-TeamViewerRestMethod { } 12 | } 13 | 14 | Describe 'Remove-TeamViewerDevice' { 15 | It 'Should call the correct API endpoint' { 16 | Remove-TeamViewerDevice -ApiToken $testApiToken -Id 'd1234' 17 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 18 | $ApiToken -eq $testApiToken -And ` 19 | $Uri -eq '//unit.test/devices/d1234' -And ` 20 | $Method -eq 'Delete' } 21 | } 22 | 23 | It 'Should accept Device objects' { 24 | $testDeviceObj = @{ device_id = 'd1234' } | ConvertTo-TeamViewerDevice 25 | Remove-TeamViewerDevice -ApiToken $testApiToken -Device $testDeviceObj 26 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 27 | $ApiToken -eq $testApiToken -And ` 28 | $Uri -eq '//unit.test/devices/d1234' -And ` 29 | $Method -eq 'Delete' } 30 | } 31 | 32 | It 'Should accept pipeline input' { 33 | $testDeviceObj = @{ device_id = 'd1234' } | ConvertTo-TeamViewerDevice 34 | $testDeviceObj | Remove-TeamViewerDevice -ApiToken $testApiToken 35 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 36 | $ApiToken -eq $testApiToken -And ` 37 | $Uri -eq '//unit.test/devices/d1234' -And ` 38 | $Method -eq 'Delete' } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Tests/Public/Remove-TeamViewerContact.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Remove-TeamViewerContact.ps1" 3 | 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 5 | ForEach-Object { . $_.FullName } 6 | 7 | $testApiToken = [securestring]@{} 8 | $null = $testApiToken 9 | 10 | Mock Get-TeamViewerApiUri { '//unit.test' } 11 | Mock Invoke-TeamViewerRestMethod { } 12 | } 13 | 14 | Describe 'Remove-TeamViewerContact' { 15 | It 'Should call the correct API endpoint' { 16 | Remove-TeamViewerContact -ApiToken $testApiToken -Id 'c1234' 17 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 18 | $ApiToken -eq $testApiToken -And ` 19 | $Uri -eq '//unit.test/contacts/c1234' -And ` 20 | $Method -eq 'Delete' } 21 | } 22 | 23 | It 'Should accept Contact objects' { 24 | $testContact = @{ contact_id = 'c1234' } | ConvertTo-TeamViewerContact 25 | Remove-TeamViewerContact -ApiToken $testApiToken -Contact $testContact 26 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 27 | $ApiToken -eq $testApiToken -And ` 28 | $Uri -eq '//unit.test/contacts/c1234' -And ` 29 | $Method -eq 'Delete' } 30 | } 31 | 32 | It 'Should accept pipeline input' { 33 | $testContact = @{ contact_id = 'c1234' } | ConvertTo-TeamViewerContact 34 | $testContact | Remove-TeamViewerContact -ApiToken $testApiToken 35 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 36 | $ApiToken -eq $testApiToken -And ` 37 | $Uri -eq '//unit.test/contacts/c1234' -And ` 38 | $Method -eq 'Delete' } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Docs/Help/Connect-TeamViewerApi.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Connect-TeamViewerApi.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Connect-TeamViewerApi 9 | 10 | ## SYNOPSIS 11 | 12 | Store the TeamViewer API access token in the current environment. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Connect-TeamViewerApi [-ApiToken] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Stores the TeamViewer API access token in the current environment such that 23 | API related function don't need to specify the `ApiToken` parameter anymore. 24 | 25 | ## EXAMPLES 26 | 27 | ### Example 1 28 | 29 | ```powershell 30 | PS /> Connect-TeamViewerApi 31 | ********************* 32 | PS /> Get-TeamViewerUser 33 | ``` 34 | 35 | Use `Connect-TeamViewerApi` to store the TeamViewer API access token as secure 36 | string in the current Powershell global scope. 37 | 38 | ## PARAMETERS 39 | 40 | ### -ApiToken 41 | 42 | The TeamViewer API access token. 43 | 44 | ```yaml 45 | Type: SecureString 46 | Parameter Sets: (All) 47 | Aliases: 48 | 49 | Required: True 50 | Position: 0 51 | Default value: None 52 | Accept pipeline input: False 53 | Accept wildcard characters: False 54 | ``` 55 | 56 | ### CommonParameters 57 | 58 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 59 | 60 | ## INPUTS 61 | 62 | ### None 63 | 64 | ## OUTPUTS 65 | 66 | ## NOTES 67 | 68 | ## RELATED LINKS 69 | 70 | [Disconnect-TeamViewerApi](Disconnect-TeamViewerApi.md) 71 | -------------------------------------------------------------------------------- /Tests/Public/Get-TeamViewerCustomModuleId.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Get-TeamViewerCustomModuleId.ps1" 3 | . "$PSScriptRoot\..\..\Cmdlets\Public\Test-TeamViewerInstallation.ps1" 4 | . "$PSScriptRoot\..\..\Cmdlets\Public\Get-TeamViewerInstallationDirectory.ps1" 5 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 6 | ForEach-Object { . $_.FullName } 7 | } 8 | 9 | Describe 'Get-TeamViewerCustomModuleId' { 10 | Context 'When TeamViewer is installed and customization is applied' { 11 | BeforeAll { 12 | Mock Test-TeamViewerInstallation { $true } 13 | Mock Test-Path { $true } 14 | Mock Get-Content { '{"id": "customModuleId"}' } 15 | Mock Get-TeamViewerInstallationDirectory {return 'C:\'} 16 | $installationDirectory = Get-TeamViewerInstallationDirectory 17 | $fileName ='TeamViewer.Json' 18 | $filePath = Join-Path -Path $installationDirectory -ChildPath $fileName 19 | Mock -CommandName Join-Path -MockWith {$filePath} 20 | } 21 | 22 | It 'Should return the custom module ID' { 23 | $expectedId = 'customModuleId' 24 | $result = Get-TeamViewerCustomModuleId 25 | $result | Should -Be $expectedId 26 | } 27 | } 28 | 29 | 30 | Context 'When TeamViewer is not installed' { 31 | BeforeAll { 32 | Mock Test-TeamViewerInstallation { $false } 33 | Mock Write-Error {} 34 | } 35 | 36 | It 'Should write an error message' { 37 | Mock Write-Error -ParameterFilter { $_ -eq 'TeamViewer is not installed' } 38 | Get-TeamViewerCustomModuleId 39 | Assert-MockCalled Write-Error -Scope It -Times 1 40 | } 41 | } 42 | 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /Tests/Public/Get-TeamViewerPredefinedRole.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\Get-TeamViewerPredefinedRole.ps1" 3 | 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 5 | ForEach-Object { . $_.FullName } 6 | 7 | $testApiToken = [securestring]@{} 8 | $null = $testApiToken 9 | 10 | Mock Get-TeamViewerApiUri { '//unit.test' } 11 | Mock Invoke-TeamViewerRestMethod { 12 | @{ PredefineduserRoleId = 'e1631449-6321-4a58-920c-5440029b092e' } 13 | } 14 | } 15 | 16 | Describe 'Get-TeamViewerPredefinedRole' { 17 | 18 | It 'Should call the correct API endpoint to list PredefinedRole' { 19 | Get-TeamViewerPredefinedRole -ApiToken $testApiToken 20 | 21 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 22 | $ApiToken -eq $testApiToken -And ` 23 | $Uri -eq '//unit.test/userroles/predefined' -And ` 24 | $Method -eq 'Get' } 25 | } 26 | 27 | It 'Should convert input object to TeamViewerPS.PrefinedRole' { 28 | $inputObject = @{ 29 | PredefineduserRoleId = 'a9c9435d-8544-4e6a-9830-9337078c9aab' 30 | } | ConvertTo-Json 31 | 32 | $result = $inputObject | ConvertFrom-Json | ConvertTo-TeamViewerPredefinedRole 33 | 34 | $result | Should -BeOfType [PSCustomObject] 35 | $result.PSObject.TypeNames | Should -Contain 'TeamViewerPS.PredefinedRole' 36 | $result.PredefinedRoleID | Should -Be 'a9c9435d-8544-4e6a-9830-9337078c9aab' 37 | } 38 | 39 | It 'Should return PredefinedRole objects' { 40 | $result = Get-TeamViewerPredefinedRole -ApiToken $testApiToken 41 | $result | Should -HaveCount 1 42 | $result[0].PSObject.TypeNames | Should -Contain 'TeamViewerPS.PredefinedRole' 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Docs/Help/Restart-TeamViewerService.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Restart-TeamViewerService.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Restart-TeamViewerService 9 | 10 | ## SYNOPSIS 11 | 12 | Restart the locally installed TeamViewer service. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Restart-TeamViewerService [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Restarts the locally installed TeamViewer service. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS /> Restart-TeamViewerService 30 | ``` 31 | 32 | ## PARAMETERS 33 | 34 | ### -Confirm 35 | 36 | Prompts you for confirmation before running the cmdlet. 37 | 38 | ```yaml 39 | Type: SwitchParameter 40 | Parameter Sets: (All) 41 | Aliases: cf 42 | 43 | Required: False 44 | Position: Named 45 | Default value: None 46 | Accept pipeline input: False 47 | Accept wildcard characters: False 48 | ``` 49 | 50 | ### -WhatIf 51 | 52 | Shows what would happen if the cmdlet runs. 53 | The cmdlet is not run. 54 | 55 | ```yaml 56 | Type: SwitchParameter 57 | Parameter Sets: (All) 58 | Aliases: wi 59 | 60 | Required: False 61 | Position: Named 62 | Default value: None 63 | Accept pipeline input: False 64 | Accept wildcard characters: False 65 | ``` 66 | 67 | ### CommonParameters 68 | 69 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 70 | 71 | ## INPUTS 72 | 73 | ### None 74 | 75 | ## OUTPUTS 76 | 77 | ## NOTES 78 | 79 | ## RELATED LINKS 80 | -------------------------------------------------------------------------------- /Cmdlets/Public/Add-TeamViewerAssignment.ps1: -------------------------------------------------------------------------------- 1 | function Add-TeamViewerAssignment { 2 | param( 3 | [Parameter(Mandatory = $true)] 4 | [object] 5 | $AssignmentId, 6 | 7 | [string] 8 | $DeviceAlias, 9 | 10 | [int] 11 | $Retries 12 | ) 13 | 14 | 15 | if (Test-TeamViewerInstallation) { 16 | $OS = Get-OperatingSystem 17 | $CurrentDirectory = Get-Location 18 | $installationDirectory = Get-TeamViewerInstallationDirectory 19 | Set-Location $installationDirectory 20 | $CurrentVersion = Get-TeamViewerVersion 21 | $VersionTable = $CurrentVersion.split('.') 22 | if ($OS -eq 'Windows') { 23 | $cmd = "assignment --id $AssignmentId" 24 | $FilePath = 'TeamViewer.exe' 25 | } 26 | elseif ($OS -eq 'Linux') { 27 | $cmd = "teamviewer assignment --id $AssignmentId" 28 | $FilePath = 'sudo' 29 | } 30 | 31 | if ($DeviceAlias) { 32 | if (($VersionTable[0] -eq 15 -and $VersionTable[1] -ge 44) -or $VersionTable[0] -gt 15) { 33 | $cmd += " --device-alias=$DeviceAlias" 34 | } 35 | else { 36 | Write-Error "Current TeamViewer Version: $CurrentVersion does not support the usage of alias. Please update to the latest version." 37 | Set-Location $CurrentDirectory 38 | exit 39 | } 40 | } 41 | if ($Retries) { 42 | $cmd += " --retries=$Retries" 43 | } 44 | $process = Start-Process -FilePath $FilePath -ArgumentList $cmd -Wait -PassThru 45 | $process.ExitCode | Resolve-AssignmentErrorCode 46 | Set-Location $CurrentDirectory 47 | } 48 | else { 49 | Write-Output 'TeamViewer is not installed.' 50 | } 51 | } 52 | 53 | 54 | -------------------------------------------------------------------------------- /Tests/Public/New-TeamViewerManagedGroup.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | . "$PSScriptRoot\..\..\Cmdlets\Public\New-TeamViewerManagedGroup.ps1" 3 | 4 | @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` 5 | ForEach-Object { . $_.FullName } 6 | 7 | $testApiToken = [securestring]@{} 8 | $null = $testApiToken 9 | $mockArgs = @{} 10 | 11 | Mock Get-TeamViewerApiUri { '//unit.test' } 12 | Mock Invoke-TeamViewerRestMethod { 13 | $mockArgs.Body = $Body 14 | @{ 15 | id = 'b5b8c706-710d-43c5-b775-dc86347d9e56' 16 | name = 'Unit Test ManagedGroup' 17 | } 18 | } 19 | } 20 | 21 | Describe 'New-TeamViewerManagedGroup' { 22 | 23 | It 'Should call the correct API endpoint' { 24 | New-TeamViewerManagedGroup -ApiToken $testApiToken -Name 'Unit Test ManagedGroup' 25 | 26 | Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { 27 | $ApiToken -eq $testApiToken -And ` 28 | $Uri -eq '//unit.test/managed/groups' -And ` 29 | $Method -eq 'Post' } 30 | } 31 | 32 | It 'Should include the given name in the request' { 33 | New-TeamViewerManagedGroup -ApiToken $testApiToken -Name 'Unit Test ManagedGroup' 34 | 35 | $mockArgs.Body | Should -Not -BeNullOrEmpty 36 | $body = [System.Text.Encoding]::UTF8.GetString($mockArgs.Body) | ConvertFrom-Json 37 | $body.name | Should -Be 'Unit Test ManagedGroup' 38 | } 39 | 40 | It 'Should return a ManagedGroup object' { 41 | $result = New-TeamViewerManagedGroup -ApiToken $testApiToken -Name 'Unit Test ManagedGroup' 42 | $result | Should -Not -BeNullOrEmpty 43 | $result | Should -BeOfType [PSObject] 44 | $result.PSObject.TypeNames | Should -Contain 'TeamViewerPS.ManagedGroup' 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Cmdlets/Public/Add-TeamViewerSsoExclusion.ps1: -------------------------------------------------------------------------------- 1 | function Add-TeamViewerSsoExclusion { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerSsoDomainId } )] 10 | [Alias("Domain")] 11 | [object] 12 | $DomainId, 13 | 14 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 15 | [string[]] 16 | $Email 17 | ) 18 | Begin { 19 | $id = $DomainId | Resolve-TeamViewerSsoDomainId 20 | $resourceUri = "$(Get-TeamViewerApiUri)/ssoDomain/$id/exclusion" 21 | $emailsToAdd = @() 22 | $null = $ApiToken # https://github.com/PowerShell/PSScriptAnalyzer/issues/1472 23 | 24 | function Invoke-RequestInternal { 25 | $body = @{ 26 | emails = @($emailsToAdd) 27 | } 28 | Invoke-TeamViewerRestMethod ` 29 | -ApiToken $ApiToken ` 30 | -Uri $resourceUri ` 31 | -Method Post ` 32 | -ContentType "application/json; charset=utf-8" ` 33 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 34 | -WriteErrorTo $PSCmdlet ` 35 | -ErrorAction Stop | ` 36 | Out-Null 37 | } 38 | } 39 | Process { 40 | if ($PSCmdlet.ShouldProcess($Email, "Add SSO exclusion")) { 41 | $emailsToAdd += $Email 42 | } 43 | if ($emailsToAdd.Length -eq 100) { 44 | Invoke-RequestInternal 45 | $emailsToAdd = @() 46 | } 47 | } 48 | End { 49 | if ($emailsToAdd.Length -gt 0) { 50 | Invoke-RequestInternal 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Docs/Help/Stop-TeamViewerService.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Stop-TeamViewerService.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Stop-TeamViewerService 9 | 10 | ## SYNOPSIS 11 | 12 | Stop the locally installed TeamViewer service. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Stop-TeamViewerService [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Stop the locally installed TeamViewer service. 23 | Nothing will happen if TeamViewer is not installed. 24 | 25 | ## EXAMPLES 26 | 27 | ### Example 1 28 | 29 | ```powershell 30 | PS /> Stop-TeamViewerService 31 | ``` 32 | 33 | ## PARAMETERS 34 | 35 | ### -Confirm 36 | 37 | Prompts you for confirmation before running the cmdlet. 38 | 39 | ```yaml 40 | Type: SwitchParameter 41 | Parameter Sets: (All) 42 | Aliases: cf 43 | 44 | Required: False 45 | Position: Named 46 | Default value: None 47 | Accept pipeline input: False 48 | Accept wildcard characters: False 49 | ``` 50 | 51 | ### -WhatIf 52 | 53 | Shows what would happen if the cmdlet runs. 54 | The cmdlet is not run. 55 | 56 | ```yaml 57 | Type: SwitchParameter 58 | Parameter Sets: (All) 59 | Aliases: wi 60 | 61 | Required: False 62 | Position: Named 63 | Default value: None 64 | Accept pipeline input: False 65 | Accept wildcard characters: False 66 | ``` 67 | 68 | ### CommonParameters 69 | 70 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 71 | 72 | ## INPUTS 73 | 74 | ### None 75 | 76 | ## OUTPUTS 77 | 78 | ## NOTES 79 | 80 | ## RELATED LINKS 81 | -------------------------------------------------------------------------------- /Tests/Private/Test-ManifestFile.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | $Script:Module_RootPath = (Resolve-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath '..\..')) 3 | $Script:Module_FilePath = (Get-ChildItem -Path (Join-Path -Path $Module_RootPath -ChildPath 'Cmdlets') -Filter '*.psm1' -File).FullName 4 | $Script:Module_Name = (Split-Path -Path $Module_FilePath -Leaf).Replace('.psm1', '') 5 | $Script:Module_ManifestFilePath = (Get-ChildItem -Path (Join-Path -Path $Module_RootPath -ChildPath 'Cmdlets') -Filter '*.psd1' -File).FullName 6 | } 7 | 8 | Context 'Test-ManifestFile' { 9 | It 'Valid module manifest file' { 10 | $Module_ManifestFilePath | Should -Exist 11 | 12 | { 13 | $Script:Module_Manifest = Test-ModuleManifest -Path $Module_ManifestFilePath -ErrorAction Stop 14 | } | Should -Not -Throw 15 | } 16 | 17 | It 'Valid manifest root module' { 18 | $Module_Manifest.RootModule | Should -Be "$Module_Name.psm1" 19 | } 20 | 21 | It 'Valid version check' { 22 | $Module_Manifest.Version -as [Version] | Should -Not -BeNullOrEmpty 23 | } 24 | 25 | It 'Valid manifest GUID' { 26 | $Module_Manifest.Guid | Should -Be 'd4e57325-dfd9-4391-8259-ce81d2aa7d48' 27 | } 28 | 29 | It 'Valid manifest author' { 30 | $Module_Manifest.Author | Should -Be 'TeamViewer Germany GmbH' 31 | } 32 | 33 | It 'Valid manifest company' { 34 | $Module_Manifest.CompanyName | Should -Be 'TeamViewer Germany GmbH' 35 | } 36 | 37 | It 'Valid manifest description' { 38 | $Module_Manifest.Description | Should -BeLike "$Module_Name*" 39 | } 40 | } 41 | 42 | <# Context 'Import module' { 43 | It "Module ($Module_Name) can be imported" { 44 | $Module_FilePath | Should -Exist 45 | 46 | { Import-Module $Module_FilePath -Force } | Should Not Throw 47 | } 48 | } #> 49 | -------------------------------------------------------------------------------- /Docs/Help/Export-TeamViewerSystemInformation.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Export-TeamViewerSystemInformation.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Export-TeamViewerSystemInformation 9 | 10 | ## SYNOPSIS 11 | 12 | Collect the files required by TeamViewer support and zip them. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Export-TeamViewerSystemInformation [[-TargetDirectory] ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Collects the files required by TeamViewer support and creates a zip file with clientID in its name. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS /> Export-TeamViewerSystemInformation 30 | ``` 31 | 32 | The zip file is created and stored in the working directory. 33 | 34 | ### Example 2 35 | 36 | ```powershell 37 | PS C:\> Export-TeamViewerSystemInformation -TargetDirectory "C:\" 38 | ``` 39 | 40 | The zip file is created and stored in the target directory 41 | 42 | ## PARAMETERS 43 | 44 | ### -TargetDirectory 45 | 46 | Specify the target directory to store TeamViewer support file. 47 | 48 | ```yaml 49 | Type: String 50 | Parameter Sets: (All) 51 | Aliases: 52 | 53 | Required: False 54 | Position: named 55 | Default value: None 56 | Accept pipeline input: False 57 | Accept wildcard characters: False 58 | ``` 59 | 60 | ### CommonParameters 61 | 62 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 63 | 64 | ## INPUTS 65 | 66 | ### None 67 | 68 | ## OUTPUTS 69 | 70 | ## NOTES 71 | 72 | ## RELATED LINKS 73 | -------------------------------------------------------------------------------- /Docs/Help/Start-TeamViewerService.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: TeamViewerPS-help.xml 3 | Module Name: TeamViewerPS 4 | online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Start-TeamViewerService.md 5 | schema: 2.0.0 6 | --- 7 | 8 | # Start-TeamViewerService 9 | 10 | ## SYNOPSIS 11 | 12 | Start the locally installed TeamViewer service. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Start-TeamViewerService [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Start the locally installed TeamViewer service. 23 | Nothing will happen if TeamViewer is not installed. 24 | 25 | ## EXAMPLES 26 | 27 | ### Example 1 28 | 29 | ```powershell 30 | PS /> Start-TeamViewerService 31 | ``` 32 | 33 | ## PARAMETERS 34 | 35 | ### -Confirm 36 | 37 | Prompts you for confirmation before running the cmdlet. 38 | 39 | ```yaml 40 | Type: SwitchParameter 41 | Parameter Sets: (All) 42 | Aliases: cf 43 | 44 | Required: False 45 | Position: Named 46 | Default value: None 47 | Accept pipeline input: False 48 | Accept wildcard characters: False 49 | ``` 50 | 51 | ### -WhatIf 52 | 53 | Shows what would happen if the cmdlet runs. 54 | The cmdlet is not run. 55 | 56 | ```yaml 57 | Type: SwitchParameter 58 | Parameter Sets: (All) 59 | Aliases: wi 60 | 61 | Required: False 62 | Position: Named 63 | Default value: None 64 | Accept pipeline input: False 65 | Accept wildcard characters: False 66 | ``` 67 | 68 | ### CommonParameters 69 | 70 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 71 | 72 | ## INPUTS 73 | 74 | ### None 75 | 76 | ## OUTPUTS 77 | 78 | ## NOTES 79 | 80 | ## RELATED LINKS 81 | -------------------------------------------------------------------------------- /Cmdlets/Public/Remove-TeamViewerSsoExclusion.ps1: -------------------------------------------------------------------------------- 1 | function Remove-TeamViewerSsoExclusion { 2 | [CmdletBinding(SupportsShouldProcess = $true)] 3 | param( 4 | [Parameter(Mandatory = $true)] 5 | [securestring] 6 | $ApiToken, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [ValidateScript( { $_ | Resolve-TeamViewerSsoDomainId } )] 10 | [Alias("Domain")] 11 | [object] 12 | $DomainId, 13 | 14 | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] 15 | [string[]] 16 | $Email 17 | ) 18 | Begin { 19 | $id = $DomainId | Resolve-TeamViewerSsoDomainId 20 | $resourceUri = "$(Get-TeamViewerApiUri)/ssoDomain/$id/exclusion" 21 | $emailsToRemove = @() 22 | $null = $ApiToken # https://github.com/PowerShell/PSScriptAnalyzer/issues/1472 23 | 24 | function Invoke-RequestInternal { 25 | $body = @{ 26 | emails = @($emailsToRemove) 27 | } 28 | Invoke-TeamViewerRestMethod ` 29 | -ApiToken $ApiToken ` 30 | -Uri $resourceUri ` 31 | -Method Delete ` 32 | -ContentType "application/json; charset=utf-8" ` 33 | -Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` 34 | -WriteErrorTo $PSCmdlet ` 35 | -ErrorAction Stop | ` 36 | Out-Null 37 | } 38 | } 39 | Process { 40 | if ($PSCmdlet.ShouldProcess($Email, "Remove SSO exclusion")) { 41 | $emailsToRemove += $Email 42 | } 43 | if ($emailsToRemove.Length -eq 100) { 44 | Invoke-RequestInternal 45 | $emailsToRemove = @() 46 | } 47 | } 48 | End { 49 | if ($emailsToRemove.Length -gt 0) { 50 | Invoke-RequestInternal 51 | } 52 | } 53 | } 54 | --------------------------------------------------------------------------------