From 3131c7cb9ec8d53f2f9fb23bf26673a7f22e8f57 Mon Sep 17 00:00:00 2001 From: radu-cristea-15 Date: Fri, 7 Nov 2025 15:27:42 +0100 Subject: [PATCH 1/3] Add new cmdlet Get-TeamViewerEffectivePermission --- .../Get-TeamViewerEffectivePermission.ps1 | 26 ++++++++ .../Help/Get-TeamViewerEffectivePermission.md | 66 +++++++++++++++++++ Docs/TeamViewerPS.md | 1 + ...et-TeamViewerEffectivePermission.Tests.ps1 | 59 +++++++++++++++++ 4 files changed, 152 insertions(+) create mode 100644 Cmdlets/Public/Get-TeamViewerEffectivePermission.ps1 create mode 100644 Docs/Help/Get-TeamViewerEffectivePermission.md create mode 100644 Tests/Public/Get-TeamViewerEffectivePermission.Tests.ps1 diff --git a/Cmdlets/Public/Get-TeamViewerEffectivePermission.ps1 b/Cmdlets/Public/Get-TeamViewerEffectivePermission.ps1 new file mode 100644 index 0000000..be94a69 --- /dev/null +++ b/Cmdlets/Public/Get-TeamViewerEffectivePermission.ps1 @@ -0,0 +1,26 @@ +function Get-TeamViewerEffectivePermission { + [CmdletBinding(DefaultParameterSetName = '')] + param( + [Parameter(Mandatory = $true)] + [securestring] + $ApiToken + ) + + Begin { + $resourceUri = "$(Get-TeamViewerApiUri)/users/effectivepermissions" + } + + Process { + $response = Invoke-TeamViewerRestMethod ` + -ApiToken $ApiToken ` + -Uri $resourceUri ` + -Method Get ` + -WriteErrorTo $PSCmdlet ` + -ErrorAction Stop + if ($null -eq $response -or $response.Count -eq 0) { + $response = @{} + } + return [PSCustomObject] $response + } +} + diff --git a/Docs/Help/Get-TeamViewerEffectivePermission.md b/Docs/Help/Get-TeamViewerEffectivePermission.md new file mode 100644 index 0000000..923c4ee --- /dev/null +++ b/Docs/Help/Get-TeamViewerEffectivePermission.md @@ -0,0 +1,66 @@ +--- +external help file: TeamViewerPS-help.xml +Module Name: TeamViewerPS +online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Get-TeamViewerEffectivePermission.md +schema: 2.0.0 +--- + +# Get-TeamViewerEffectivePermission + +## SYNOPSIS + +Lists all effective permissions in a TeamViewer company. + +## SYNTAX + +```powershell +Get-TeamViewerEffectivePermission [-ApiToken] [] +``` + +## DESCRIPTION + +Lists all effective permissions in the TeamViewer company associated with the API access token. + +## EXAMPLES + +### Example 1 + +```powershell +PS /> Get-TeamViewerEffectivePermission +``` + +Lists all effective permissions. + +## PARAMETERS + +### -ApiToken + +The TeamViewer API access token. + +```yaml +Type: SecureString +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters + +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). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object + +## NOTES + +## RELATED LINKS \ No newline at end of file diff --git a/Docs/TeamViewerPS.md b/Docs/TeamViewerPS.md index d9e200a..e077a17 100644 --- a/Docs/TeamViewerPS.md +++ b/Docs/TeamViewerPS.md @@ -77,6 +77,7 @@ The following functions are available in this category: [`Remove-TeamViewerUserTFA`](Help/Remove-TeamViewerUserTFA.md) +['Get-TeamViewerEffectivePermission'](Help/Get-TeamViewerEffectivePermission.md) ## User Groups diff --git a/Tests/Public/Get-TeamViewerEffectivePermission.Tests.ps1 b/Tests/Public/Get-TeamViewerEffectivePermission.Tests.ps1 new file mode 100644 index 0000000..dbe34a4 --- /dev/null +++ b/Tests/Public/Get-TeamViewerEffectivePermission.Tests.ps1 @@ -0,0 +1,59 @@ +BeforeAll { + . "$PSScriptRoot\..\..\Cmdlets\Public\Get-TeamViewerEffectivePermission.ps1" + + @(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` + ForEach-Object { . $_.FullName } + + $testApiToken = [securestring]@{} + $null = $testApiToken + + Mock Get-TeamViewerApiUri { '//unit.test' } + Mock Invoke-TeamViewerRestMethod { + @{ + AllowGroupSharing = $true + ManageAdmins = $false + ManageUsers = $true + ModifyConnections = $true + DeleteConnections = $true + } + } +} + +Describe 'Get-TeamViewerEffectivePermission' { + + It 'Should call the correct API endpoint to list permission' { + Get-TeamViewerEffectivePermission -ApiToken $testApiToken + + Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { + $ApiToken -eq $testApiToken -And ` + $Uri -eq '//unit.test/users/effectivepermissions' -And ` + $Method -eq 'Get' } + } + + It 'Should convert input object to TeamViewerPS.EffectivePermission' { + + $result = Get-TeamViewerEffectivePermission -ApiToken $testApiToken + + $result | Should -BeOfType [PSCustomObject] + $result.AllowGroupSharing | Should -Be $true + $result.ManageAdmins | Should -Be $false + $result.ManageUsers | Should -Be $true + $result.ModifyConnections | Should -Be $true + } + + It 'Should return an empty object if no permissions are assigned' { + Mock Invoke-TeamViewerRestMethod { + @{ + } + } + + $result = Get-TeamViewerEffectivePermission -ApiToken $testApiToken + $result | Should -BeOfType [PSCustomObject] + $result.PSObject.Properties | Should -Be $null + Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { + $ApiToken -eq $testApiToken -And ` + $Uri -eq '//unit.test/users/effectivepermissions' -And ` + $Method -eq 'Get' } + } + +} \ No newline at end of file From 4c6be6d85c482a4bd93d76653b8511a13e6e77f9 Mon Sep 17 00:00:00 2001 From: Radu Cristea Date: Fri, 21 Nov 2025 11:34:01 +0100 Subject: [PATCH 2/3] Updated the set-manageddevice function with additional description endpoint --- .../Public/Set-TeamViewerManagedDevice.ps1 | 31 ++++++++++++--- .../Set-TeamViewerManagedDevice.Tests.ps1 | 39 +++++++++++++++++-- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/Cmdlets/Public/Set-TeamViewerManagedDevice.ps1 b/Cmdlets/Public/Set-TeamViewerManagedDevice.ps1 index d047331..2c5a569 100644 --- a/Cmdlets/Public/Set-TeamViewerManagedDevice.ps1 +++ b/Cmdlets/Public/Set-TeamViewerManagedDevice.ps1 @@ -23,9 +23,14 @@ function Set-TeamViewerManagedDevice { [ValidateScript( { $_ | Resolve-TeamViewerManagedGroupId } )] [Alias('ManagedGroupId')] [object] - $ManagedGroup + $ManagedGroup, + + [Parameter(ParameterSetName = 'UpdateDescription')] + [Alias('Description')] + [string] + $deviceDescription ) - Begin { + begin { $body = @{} if ($Name) { @@ -38,10 +43,20 @@ function Set-TeamViewerManagedDevice { $body['managedGroupId'] = $ManagedGroup | Resolve-TeamViewerManagedGroupId } - if ($Policy -And $ManagedGroup) { + if ($Policy -and $ManagedGroup) { $PSCmdlet.ThrowTerminatingError( ('The combination of parameters -Policy and -ManagedGroup is not allowed.' | ` - ConvertTo-ErrorRecord -ErrorCategory InvalidArgument)) + ConvertToErrorRecord -ErrorCategory InvalidArgument)) + } + + if ($deviceDescription -and ($Policy -or $ManagedGroup)) { + $PSCmdlet.ThrowTerminatingError( + ('The parameter -deviceDescription cannot be combined with -Policy or -ManagedGroup.' | + ConvertTo-ErrorRecord -ErrorCategory InvalidArgument)) + } + + if ($deviceDescription) { + $body['deviceDescription'] = $deviceDescription } if ($body.Count -eq 0) { @@ -50,10 +65,16 @@ function Set-TeamViewerManagedDevice { ConvertTo-ErrorRecord -ErrorCategory InvalidArgument)) } } - Process { + process { $deviceId = $Device | Resolve-TeamViewerManagedDeviceId $resourceUri = "$(Get-TeamViewerApiUri)/managed/devices/$deviceId" + switch ($PsCmdlet.ParameterSetName) { + 'UpdateDescription' { + $resourceUri += '/description' + } + } + if ($PSCmdlet.ShouldProcess($Device.ToString(), 'Change managed device entry')) { Invoke-TeamViewerRestMethod ` -ApiToken $ApiToken ` diff --git a/Tests/Public/Set-TeamViewerManagedDevice.Tests.ps1 b/Tests/Public/Set-TeamViewerManagedDevice.Tests.ps1 index 3e8fd17..76636dd 100644 --- a/Tests/Public/Set-TeamViewerManagedDevice.Tests.ps1 +++ b/Tests/Public/Set-TeamViewerManagedDevice.Tests.ps1 @@ -19,8 +19,8 @@ Describe 'Set-TeamViewerManagedDevice' { It 'Should call the correct API endpoint to update a managed device' { Set-TeamViewerManagedDevice -ApiToken $testApiToken -Device $testDeviceId -Name 'Foo Bar' Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { - $ApiToken -eq $testApiToken -And ` - $Uri -eq "//unit.test/managed/devices/$testDeviceId" -And ` + $ApiToken -eq $testApiToken -and ` + $Uri -eq "//unit.test/managed/devices/$testDeviceId" -and ` $Method -eq 'Put' } } @@ -45,6 +45,37 @@ Describe 'Set-TeamViewerManagedDevice' { $body.managedGroupId | Should -Be 'e579cfeb-0b29-4d91-9e81-2d9507f53ff8' } + It 'Should update the managed device description' { + Set-TeamViewerManagedDevice -ApiToken $testApiToken -Device $testDeviceId -deviceDescription 'Test description' + $mockArgs.Body | Should -Not -BeNullOrEmpty + + $body = [System.Text.Encoding]::UTF8.GetString($mockArgs.Body) | ConvertFrom-Json + $body.deviceDescription | Should -Be 'Test description' + + Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { + $ApiToken -eq $testApiToken -and ` + $Uri -eq "//unit.test/managed/devices/$testDeviceId/description" -and ` + $Method -eq 'Put' + } + } + + It 'Should not allow description together with policy' { + { Set-TeamViewerManagedDevice ` + -ApiToken $testApiToken ` + -Device $testDeviceId ` + -deviceDescription 'Test description' ` + -Policy '2871c013-3040-4969-9ba4-ce970f4375e8' } | Should -Throw + } + + It 'Should not allow description together with managed group' { + { Set-TeamViewerManagedDevice ` + -ApiToken $testApiToken ` + -Device $testDeviceId ` + -deviceDescription 'Test description' ` + -ManagedGroup 'e579cfeb-0b29-4d91-9e81-2d9507f53ff8' } | Should -Throw + } + + It 'Should not be possible to inherit and set a policy at the same time' { { Set-TeamViewerManagedDevice ` -ApiToken $testApiToken ` @@ -68,8 +99,8 @@ Describe 'Set-TeamViewerManagedDevice' { $testDevice = @{ id = $testDeviceId; name = 'test device' } | ConvertTo-TeamViewerManagedDevice Set-TeamViewerManagedDevice -ApiToken $testApiToken -Device $testDevice -Name 'Foo Bar' Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { - $ApiToken -eq $testApiToken -And ` - $Uri -eq "//unit.test/managed/devices/$testDeviceId" -And ` + $ApiToken -eq $testApiToken -and ` + $Uri -eq "//unit.test/managed/devices/$testDeviceId" -and ` $Method -eq 'Put' } } From c54d6d48d437a8a1c2f8c9e2e9f56e7645cc0fc0 Mon Sep 17 00:00:00 2001 From: Radu Cristea Date: Fri, 21 Nov 2025 11:34:01 +0100 Subject: [PATCH 3/3] Updated the set-manageddevice function with additional description endpoint --- .../Public/Set-TeamViewerManagedDevice.ps1 | 31 ++++++++++++--- .../Set-TeamViewerManagedDevice.Tests.ps1 | 39 +++++++++++++++++-- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/Cmdlets/Public/Set-TeamViewerManagedDevice.ps1 b/Cmdlets/Public/Set-TeamViewerManagedDevice.ps1 index d047331..2c5a569 100644 --- a/Cmdlets/Public/Set-TeamViewerManagedDevice.ps1 +++ b/Cmdlets/Public/Set-TeamViewerManagedDevice.ps1 @@ -23,9 +23,14 @@ function Set-TeamViewerManagedDevice { [ValidateScript( { $_ | Resolve-TeamViewerManagedGroupId } )] [Alias('ManagedGroupId')] [object] - $ManagedGroup + $ManagedGroup, + + [Parameter(ParameterSetName = 'UpdateDescription')] + [Alias('Description')] + [string] + $deviceDescription ) - Begin { + begin { $body = @{} if ($Name) { @@ -38,10 +43,20 @@ function Set-TeamViewerManagedDevice { $body['managedGroupId'] = $ManagedGroup | Resolve-TeamViewerManagedGroupId } - if ($Policy -And $ManagedGroup) { + if ($Policy -and $ManagedGroup) { $PSCmdlet.ThrowTerminatingError( ('The combination of parameters -Policy and -ManagedGroup is not allowed.' | ` - ConvertTo-ErrorRecord -ErrorCategory InvalidArgument)) + ConvertToErrorRecord -ErrorCategory InvalidArgument)) + } + + if ($deviceDescription -and ($Policy -or $ManagedGroup)) { + $PSCmdlet.ThrowTerminatingError( + ('The parameter -deviceDescription cannot be combined with -Policy or -ManagedGroup.' | + ConvertTo-ErrorRecord -ErrorCategory InvalidArgument)) + } + + if ($deviceDescription) { + $body['deviceDescription'] = $deviceDescription } if ($body.Count -eq 0) { @@ -50,10 +65,16 @@ function Set-TeamViewerManagedDevice { ConvertTo-ErrorRecord -ErrorCategory InvalidArgument)) } } - Process { + process { $deviceId = $Device | Resolve-TeamViewerManagedDeviceId $resourceUri = "$(Get-TeamViewerApiUri)/managed/devices/$deviceId" + switch ($PsCmdlet.ParameterSetName) { + 'UpdateDescription' { + $resourceUri += '/description' + } + } + if ($PSCmdlet.ShouldProcess($Device.ToString(), 'Change managed device entry')) { Invoke-TeamViewerRestMethod ` -ApiToken $ApiToken ` diff --git a/Tests/Public/Set-TeamViewerManagedDevice.Tests.ps1 b/Tests/Public/Set-TeamViewerManagedDevice.Tests.ps1 index 3e8fd17..76636dd 100644 --- a/Tests/Public/Set-TeamViewerManagedDevice.Tests.ps1 +++ b/Tests/Public/Set-TeamViewerManagedDevice.Tests.ps1 @@ -19,8 +19,8 @@ Describe 'Set-TeamViewerManagedDevice' { It 'Should call the correct API endpoint to update a managed device' { Set-TeamViewerManagedDevice -ApiToken $testApiToken -Device $testDeviceId -Name 'Foo Bar' Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { - $ApiToken -eq $testApiToken -And ` - $Uri -eq "//unit.test/managed/devices/$testDeviceId" -And ` + $ApiToken -eq $testApiToken -and ` + $Uri -eq "//unit.test/managed/devices/$testDeviceId" -and ` $Method -eq 'Put' } } @@ -45,6 +45,37 @@ Describe 'Set-TeamViewerManagedDevice' { $body.managedGroupId | Should -Be 'e579cfeb-0b29-4d91-9e81-2d9507f53ff8' } + It 'Should update the managed device description' { + Set-TeamViewerManagedDevice -ApiToken $testApiToken -Device $testDeviceId -deviceDescription 'Test description' + $mockArgs.Body | Should -Not -BeNullOrEmpty + + $body = [System.Text.Encoding]::UTF8.GetString($mockArgs.Body) | ConvertFrom-Json + $body.deviceDescription | Should -Be 'Test description' + + Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { + $ApiToken -eq $testApiToken -and ` + $Uri -eq "//unit.test/managed/devices/$testDeviceId/description" -and ` + $Method -eq 'Put' + } + } + + It 'Should not allow description together with policy' { + { Set-TeamViewerManagedDevice ` + -ApiToken $testApiToken ` + -Device $testDeviceId ` + -deviceDescription 'Test description' ` + -Policy '2871c013-3040-4969-9ba4-ce970f4375e8' } | Should -Throw + } + + It 'Should not allow description together with managed group' { + { Set-TeamViewerManagedDevice ` + -ApiToken $testApiToken ` + -Device $testDeviceId ` + -deviceDescription 'Test description' ` + -ManagedGroup 'e579cfeb-0b29-4d91-9e81-2d9507f53ff8' } | Should -Throw + } + + It 'Should not be possible to inherit and set a policy at the same time' { { Set-TeamViewerManagedDevice ` -ApiToken $testApiToken ` @@ -68,8 +99,8 @@ Describe 'Set-TeamViewerManagedDevice' { $testDevice = @{ id = $testDeviceId; name = 'test device' } | ConvertTo-TeamViewerManagedDevice Set-TeamViewerManagedDevice -ApiToken $testApiToken -Device $testDevice -Name 'Foo Bar' Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { - $ApiToken -eq $testApiToken -And ` - $Uri -eq "//unit.test/managed/devices/$testDeviceId" -And ` + $ApiToken -eq $testApiToken -and ` + $Uri -eq "//unit.test/managed/devices/$testDeviceId" -and ` $Method -eq 'Put' } }