Skip to content

Commit 5691adb

Browse files
updated get-teamviewerrole function with permissions
1 parent 3982cad commit 5691adb

File tree

6 files changed

+163
-30
lines changed

6 files changed

+163
-30
lines changed

Cmdlets/Public/Get-TeamViewerRole.ps1

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,35 @@ function Get-TeamViewerRole {
33
param(
44
[Parameter(Mandatory = $true)]
55
[securestring]
6-
$ApiToken
6+
$ApiToken,
7+
8+
[switch]
9+
[Alias('ListPermissions')]
10+
$Permissions
711
)
812

9-
Begin{
10-
$parameters = @{ }
11-
$resourceUri = "$(Get-TeamViewerApiUri)/userroles"
13+
Begin {
14+
$parameters = @{ }
15+
$resourceUri = "$(Get-TeamViewerApiUri)/userroles"
16+
if ($Permissions) {
17+
$resourceUri += '/permissions'
18+
}
1219
}
1320

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.Roles | ConvertTo-TeamViewerRole )
23-
}
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+
}
2436
}
37+

Cmdlets/Public/Set-TeamViewerManagedDevice.ps1

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,64 @@
11
function Set-TeamViewerManagedDevice {
22
[CmdletBinding(SupportsShouldProcess = $true)]
33
param(
4-
[Parameter(Mandatory = $true)]
4+
[Parameter(Mandatory = $true, ParameterSetName = 'Default')]
5+
[Parameter(Mandatory = $true, ParameterSetName = 'ByPolicyId')]
6+
[Parameter(Mandatory = $true, ParameterSetName = 'ByManagedGroupId')]
7+
[Parameter(Mandatory = $true, ParameterSetName = 'UpdateDescription')]
58
[securestring]
69
$ApiToken,
710

8-
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
11+
[Parameter(Mandatory = $true, ParameterSetName = 'Default', ValueFromPipeline = $true)]
12+
[Parameter(Mandatory = $true, ParameterSetName = 'ByPolicyId', ValueFromPipeline = $true)]
13+
[Parameter(Mandatory = $true, ParameterSetName = 'ByManagedGroupId', ValueFromPipeline = $true)]
14+
[Parameter(Mandatory = $true, ParameterSetName = 'UpdateDescription', ValueFromPipeline = $true)]
915
[ValidateScript( { $_ | Resolve-TeamViewerManagedDeviceId } )]
1016
[Alias('DeviceId')]
1117
[object]
1218
$Device,
1319

20+
[Parameter(Mandatory = $false, ParameterSetName = 'Default')]
21+
[Parameter(Mandatory = $false, ParameterSetName = 'ByPolicyId')]
22+
[Parameter(Mandatory = $false, ParameterSetName = 'ByManagedGroupId')]
23+
[Parameter(Mandatory = $false, ParameterSetName = 'UpdateDescription')]
1424
[Alias('Alias')]
1525
[string]
1626
$Name,
1727

28+
[Parameter(Mandatory = $true, ParameterSetName = 'ByPolicyId')]
1829
[ValidateScript( { $_ | Resolve-TeamViewerPolicyId } )]
1930
[Alias('PolicyId')]
2031
[object]
2132
$Policy,
2233

34+
[Parameter(Mandatory = $true, ParameterSetName = 'ByManagedGroupId')]
2335
[ValidateScript( { $_ | Resolve-TeamViewerManagedGroupId } )]
2436
[Alias('ManagedGroupId')]
2537
[object]
26-
$ManagedGroup
38+
$ManagedGroup,
39+
40+
[Parameter(Mandatory = $true, ParameterSetName = 'UpdateDescription')]
41+
[Alias('DeviceDescription')]
42+
[string]
43+
$Description
2744
)
2845
Begin {
2946
$body = @{}
3047

3148
if ($Name) {
3249
$body['name'] = $Name
3350
}
34-
if ($Policy) {
35-
$body['teamviewerPolicyId'] = $Policy | Resolve-TeamViewerPolicyId
36-
}
37-
elseif ($ManagedGroup) {
38-
$body['managedGroupId'] = $ManagedGroup | Resolve-TeamViewerManagedGroupId
39-
}
4051

41-
if ($Policy -And $ManagedGroup) {
42-
$PSCmdlet.ThrowTerminatingError(
43-
('The combination of parameters -Policy and -ManagedGroup is not allowed.' | `
44-
ConvertTo-ErrorRecord -ErrorCategory InvalidArgument))
52+
switch ($PsCmdlet.ParameterSetName) {
53+
'ByPolicyId' {
54+
$body['teamviewerPolicyId'] = $Policy | Resolve-TeamViewerPolicyId
55+
}
56+
'ByManagedGroupId' {
57+
$body['managedGroupId'] = $ManagedGroup | Resolve-TeamViewerManagedGroupId
58+
}
59+
'UpdateDescription' {
60+
$body['deviceDescription'] = $Description
61+
}
4562
}
4663

4764
if ($body.Count -eq 0) {
@@ -54,6 +71,12 @@ function Set-TeamViewerManagedDevice {
5471
$deviceId = $Device | Resolve-TeamViewerManagedDeviceId
5572
$resourceUri = "$(Get-TeamViewerApiUri)/managed/devices/$deviceId"
5673

74+
switch ($PsCmdlet.ParameterSetName) {
75+
'UpdateDescription' {
76+
$resourceUri += '/description'
77+
}
78+
}
79+
5780
if ($PSCmdlet.ShouldProcess($Device.ToString(), 'Change managed device entry')) {
5881
Invoke-TeamViewerRestMethod `
5982
-ApiToken $ApiToken `

Docs/Help/Get-TeamViewerRole.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Lists all roles and their permissions in a TeamViewer company.
1414
## SYNTAX
1515

1616
```powershell
17-
Get-TeamViewerRole [-ApiToken] <SecureString> [<CommonParameters>]
17+
Get-TeamViewerRole [-ApiToken] <SecureString> [-Permissions] [<CommonParameters>]
1818
```
1919

2020
## DESCRIPTION
@@ -31,6 +31,15 @@ PS /> Get-TeamViewerRole
3131

3232
Lists all roles and their permissions.
3333

34+
### Example 2
35+
36+
```powershell
37+
PS /> Get-TeamViewerRole -ApiToken $token -Permissions
38+
```
39+
40+
Lists all the possible permissions.
41+
42+
3443
## PARAMETERS
3544

3645
### -ApiToken
@@ -48,6 +57,21 @@ Default value: None
4857
Accept pipeline input: False
4958
Accept wildcard characters: False
5059
```
60+
### -Permissions
61+
62+
The Permission definitions of a role.
63+
64+
```yaml
65+
Type: SecureString
66+
Parameter Sets: (All)
67+
Aliases: ListPermissions
68+
69+
Required: False
70+
Position: 1
71+
Default value: None
72+
Accept pipeline input: False
73+
Accept wildcard characters: False
74+
```
5175
5276
### CommonParameters
5377
@@ -66,3 +90,4 @@ An array of `TeamViewerPS.Role` objects.
6690
## NOTES
6791

6892
## RELATED LINKS
93+

Docs/Help/Set-TeamViewerManagedDevice.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ Change properties of a TeamViewer managed device.
1515

1616
```powershell
1717
Set-TeamViewerManagedDevice [-ApiToken] <SecureString> [-Device] <Object> [[-Name] <String>]
18-
[[-Policy] <Object>] [[-ManagedGroup] <Object>] [-WhatIf] [-Confirm] [<CommonParameters>]
18+
[[-Policy] <Object>] [[-ManagedGroup] <Object>] [[-Description] <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
1919
```
2020

2121
## DESCRIPTION
2222

2323
Changes properties of a managed device. For example, the name of the managed
24-
device or the policy can be changed.
24+
device or the policy or the description can be changed.
25+
You cannot combine any of those three parameters together.
2526

2627
For changing the device name, the current account needs `DeviceAdministration`
2728
manager permissions on the device.
@@ -55,6 +56,14 @@ PS /> Set-TeamViewerManagedDevice -Device '33a2e2e1-27ef-43e2-a175-f97ee0344033'
5556

5657
Inherit the TeamViewer policy from a managed group to the device (the device has to be part of the managed group specified).
5758

59+
### Example 4
60+
61+
```powershell
62+
PS /> Set-TeamViewerManagedDevice -Device '33a2e2e1-27ef-43e2-a175-f97ee0344033' -Description 'Test description'
63+
```
64+
65+
Changes the description of the device.
66+
5867
## PARAMETERS
5968

6069
### -ApiToken
@@ -159,6 +168,22 @@ Accept pipeline input: True (ByValue)
159168
Accept wildcard characters: False
160169
```
161170
171+
### -Description
172+
173+
New description for the managed device.
174+
175+
```yaml
176+
Type: String
177+
Parameter Sets: (All)
178+
Aliases: DeviceDescription
179+
180+
Required: True
181+
Position: Named
182+
Default value: None
183+
Accept pipeline input: False
184+
Accept wildcard characters: False
185+
```
186+
162187
### -WhatIf
163188
164189
Shows what would happen if the cmdlet runs.

Tests/Public/Get-TeamViewerRole.Tests.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ Describe 'Get-TeamViewerRole' {
6161
$Uri -eq '//unit.test/userroles' -And `
6262
$Method -eq 'Get' }
6363
}
64+
It 'Should call the correct API endpoint to list permissions' {
65+
Get-TeamViewerRole -ApiToken $testApiToken -Permissions
66+
67+
Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter {
68+
$ApiToken -eq $testApiToken -And `
69+
$Uri -eq '//unit.test/userroles/permissions' -And `
70+
$Method -eq 'Get' }
71+
}
6472

6573
It 'Should return Role objects' {
6674
$result = Get-TeamViewerRole -ApiToken $testApiToken

Tests/Public/Set-TeamViewerManagedDevice.Tests.ps1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,45 @@ Describe 'Set-TeamViewerManagedDevice' {
4545
$body.managedGroupId | Should -Be 'e579cfeb-0b29-4d91-9e81-2d9507f53ff8'
4646
}
4747

48+
It 'Should update the managed device alias and the managed device policy to the managed group' {
49+
Set-TeamViewerManagedDevice -ApiToken $testApiToken -Device $testDeviceId -Name 'Foo Bar' -ManagedGroup 'e579cfeb-0b29-4d91-9e81-2d9507f53ff8'
50+
$mockArgs.Body | Should -Not -BeNullOrEmpty
51+
$body = [System.Text.Encoding]::UTF8.GetString($mockArgs.Body) | ConvertFrom-Json
52+
$body.name | Should -Be 'Foo Bar'
53+
$body.managedGroupId | Should -Be 'e579cfeb-0b29-4d91-9e81-2d9507f53ff8'
54+
}
55+
56+
It 'Should update the managed device description' {
57+
Set-TeamViewerManagedDevice -ApiToken $testApiToken -Device $testDeviceId -Description 'Test description'
58+
$mockArgs.Body | Should -Not -BeNullOrEmpty
59+
60+
$body = [System.Text.Encoding]::UTF8.GetString($mockArgs.Body) | ConvertFrom-Json
61+
$body.deviceDescription | Should -Be 'Test description'
62+
63+
Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter {
64+
$ApiToken -eq $testApiToken -And `
65+
$Uri -eq "//unit.test/managed/devices/$testDeviceId/description" -And `
66+
$Method -eq 'Put'
67+
}
68+
}
69+
70+
It 'Should not allow description together with policy' {
71+
{ Set-TeamViewerManagedDevice `
72+
-ApiToken $testApiToken `
73+
-Device $testDeviceId `
74+
-Description 'Test description' `
75+
-Policy '2871c013-3040-4969-9ba4-ce970f4375e8' } | Should -Throw
76+
}
77+
78+
It 'Should not allow description together with managed group' {
79+
{ Set-TeamViewerManagedDevice `
80+
-ApiToken $testApiToken `
81+
-Device $testDeviceId `
82+
-Description 'Test description' `
83+
-ManagedGroup 'e579cfeb-0b29-4d91-9e81-2d9507f53ff8' } | Should -Throw
84+
}
85+
86+
4887
It 'Should not be possible to inherit and set a policy at the same time' {
4988
{ Set-TeamViewerManagedDevice `
5089
-ApiToken $testApiToken `

0 commit comments

Comments
 (0)