Skip to content

Commit a0365a7

Browse files
Merge pull request #77 from teamviewer/TEAM-60324_add_Get-TeamViewerCompanyManagedDevice
Added Get-TeamViewerCompanyManagedDevice cmdlet
2 parents f8a07e8 + 60caf28 commit a0365a7

File tree

6 files changed

+172
-2
lines changed

6 files changed

+172
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Change Log
22

3-
## 2.0.1 (2024-11-14)
3+
## 2.1.0 (2024-11-15)
4+
5+
### Added
6+
7+
- Adds `Get-TeamViewerCompanyManagedDevice` to return all company-managed devices.
8+
9+
## 2.0.2 (2024-11-14)
410

511
### Added
612
- Add-TeamViewerSsoInclusion command to add SSO Inclusion list items.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}

Cmdlets/TeamViewerPS.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
RootModule = 'TeamViewerPS.psm1'
44

55
# Version number of this module.
6-
ModuleVersion = '2.0.2'
6+
ModuleVersion = '2.1.0'
77

88
# Supported PSEditions.
99
# CompatiblePSEditions = @()
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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-TeamViewerCompanyManagedDevice.md
5+
schema: 2.0.0
6+
---
7+
8+
# Get-TeamViewerCompanyManagedDevice
9+
10+
## SYNOPSIS
11+
12+
Retrieves TeamViewer company-managed devices. Requires an API Token with company admin permissions.
13+
14+
## SYNTAX
15+
16+
### List (Default)
17+
18+
```powershell
19+
Get-TeamViewerCompanyManagedDevice -ApiToken <SecureString> [<CommonParameters>]
20+
```
21+
22+
## DESCRIPTION
23+
24+
Retrieves company-managed devices of the company that is associated with the API access token.
25+
26+
## EXAMPLES
27+
28+
### Example 1
29+
30+
```powershell
31+
32+
PS /> Get-TeamViewerCompanyManagedDevice
33+
```
34+
35+
List all company-managed devices of this company.
36+
37+
## PARAMETERS
38+
39+
### -ApiToken
40+
41+
The TeamViewer API access token. Needs to have company admin permissions to successfully retrieve the devices.
42+
43+
```yaml
44+
Type: SecureString
45+
Parameter Sets: (All)
46+
Aliases:
47+
48+
Required: True
49+
Position: Named
50+
Default value: None
51+
Accept pipeline input: False
52+
Accept wildcard characters: False
53+
```
54+
55+
### CommonParameters
56+
57+
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).
58+
59+
## INPUTS
60+
61+
### None
62+
63+
## OUTPUTS
64+
65+
## NOTES
66+
67+
## RELATED LINKS
68+
69+
[Get-TeamViewerManagedDevice](Get-TeamViewerManagedDevice.md)
70+
71+
[Get-TeamViewerManagedGroup](Get-TeamViewerManagedGroup.md)
72+
73+
[Get-TeamViewerManagementId](Get-TeamViewerManagementId.md)

Docs/TeamViewerPS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ The following functions are available in this category:
133133

134134
[`Get-TeamViewerManagedGroup`](Help/Get-TeamViewerManagedGroup.md)
135135

136+
[`Get-TeamViewerCompanyManagedDevice`](Help/Get-TeamViewerCompanyManagedDevice.md)
137+
136138
[`Get-TeamViewerManagementId`](Help/Get-TeamViewerManagementId.md)
137139

138140
[`Get-TeamViewerManager`](Help/Get-TeamViewerManager.md)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
BeforeAll {
2+
. "$PSScriptRoot\..\..\Cmdlets\Public\Get-TeamViewerCompanyManagedDevice.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+
}
12+
13+
Describe 'Get-TeamViewerCompanyManagedDevice' {
14+
Context 'AllDevices' {
15+
BeforeAll {
16+
Mock Invoke-TeamViewerRestMethod { @{
17+
nextPaginationToken = $null
18+
resources = @(
19+
@{ id = 'ae222e9d-a665-4cea-85b7-d4a3a08a5e35'; name = 'test company-managed device 1' },
20+
@{ id = '6cbfcfb2-a929-4987-a91b-89e2945412cf'; name = 'test company-managed device 2' },
21+
@{ id = '99a87bed-3d60-46f2-a869-b7e67a6bf2c8'; name = 'test company-managed device 3' }
22+
)
23+
} }
24+
}
25+
26+
It 'Should call the correct API endpoint to list company-managed devices' {
27+
Get-TeamViewerCompanyManagedDevice -ApiToken $testApiToken
28+
29+
$base_test_path = '//unit.test'
30+
$desired_endpoint = 'managed/devices/company'
31+
32+
Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter {
33+
$ApiToken -eq $testApiToken -And `
34+
$Uri -eq "$base_test_path/$desired_endpoint" -And `
35+
$Method -eq 'Get' }
36+
}
37+
38+
It 'Should return ManagedDevice objects' {
39+
$result = Get-TeamViewerCompanyManagedDevice -ApiToken $testApiToken
40+
$result | Should -HaveCount 3
41+
$result[0].PSObject.TypeNames | Should -Contain 'TeamViewerPS.ManagedDevice'
42+
}
43+
44+
It 'Should fetch consecutive pages' {
45+
Mock Invoke-TeamViewerRestMethod { @{
46+
nextPaginationToken = 'abc'
47+
resources = @(
48+
@{ id = 'ae222e9d-a665-4cea-85b7-d4a3a08a5e35'; name = 'test company-managed device 1' },
49+
@{ id = '6cbfcfb2-a929-4987-a91b-89e2945412cf'; name = 'test company-managed device 2' },
50+
@{ id = '99a87bed-3d60-46f2-a869-b7e67a6bf2c8'; name = 'test company-managed device 3' }
51+
)
52+
} }
53+
Mock Invoke-TeamViewerRestMethod { @{
54+
nextPaginationToken = $null
55+
resources = @(
56+
@{ id = '76e699b7-2559-4202-bf7b-c6af6929aa15'; name = 'test company-managed device 4' }
57+
)
58+
} } -ParameterFilter { $Body -And $Body['paginationToken'] -eq 'abc' }
59+
60+
$result = Get-TeamViewerCompanyManagedDevice -ApiToken $testApiToken
61+
$result | Should -HaveCount 4
62+
63+
Assert-MockCalled Invoke-TeamViewerRestMethod -Times 2 -Scope It
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)