Skip to content

Commit 1d0c773

Browse files
Updated the set-teamviewermanageddevice function with additional description endpoint
1 parent 3982cad commit 1d0c773

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

Cmdlets/Public/Set-TeamViewerManagedDevice.ps1

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ function Set-TeamViewerManagedDevice {
2323
[ValidateScript( { $_ | Resolve-TeamViewerManagedGroupId } )]
2424
[Alias('ManagedGroupId')]
2525
[object]
26-
$ManagedGroup
26+
$ManagedGroup,
27+
28+
[Parameter(ParameterSetName = 'UpdateDescription')]
29+
[Alias('DeviceDescription')]
30+
[string]
31+
$Description
2732
)
2833
Begin {
2934
$body = @{}
@@ -41,7 +46,17 @@ function Set-TeamViewerManagedDevice {
4146
if ($Policy -And $ManagedGroup) {
4247
$PSCmdlet.ThrowTerminatingError(
4348
('The combination of parameters -Policy and -ManagedGroup is not allowed.' | `
44-
ConvertTo-ErrorRecord -ErrorCategory InvalidArgument))
49+
ConvertToErrorRecord -ErrorCategory InvalidArgument))
50+
}
51+
52+
if ($Description -And ($Policy -or $ManagedGroup)) {
53+
$PSCmdlet.ThrowTerminatingError(
54+
('The parameter -Description cannot be combined with -Policy or -ManagedGroup.' |
55+
ConvertTo-ErrorRecord -ErrorCategory InvalidArgument))
56+
}
57+
58+
if ($Description) {
59+
$body['deviceDescription'] = $Description
4560
}
4661

4762
if ($body.Count -eq 0) {
@@ -54,6 +69,12 @@ function Set-TeamViewerManagedDevice {
5469
$deviceId = $Device | Resolve-TeamViewerManagedDeviceId
5570
$resourceUri = "$(Get-TeamViewerApiUri)/managed/devices/$deviceId"
5671

72+
switch ($PsCmdlet.ParameterSetName) {
73+
'UpdateDescription' {
74+
$resourceUri += '/description'
75+
}
76+
}
77+
5778
if ($PSCmdlet.ShouldProcess($Device.ToString(), 'Change managed device entry')) {
5879
Invoke-TeamViewerRestMethod `
5980
-ApiToken $ApiToken `

Tests/Public/Set-TeamViewerManagedDevice.Tests.ps1

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

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

0 commit comments

Comments
 (0)