-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from teamviewer/TEAM-60324_add_Get-TeamViewerC…
…ompanyManagedDevice Added Get-TeamViewerCompanyManagedDevice cmdlet
- Loading branch information
Showing
6 changed files
with
172 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function Get-TeamViewerCompanyManagedDevice { | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[securestring] | ||
$ApiToken | ||
) | ||
|
||
$resourceUri = "$(Get-TeamViewerApiUri)/managed/devices/company" | ||
$parameters = @{} | ||
|
||
do { | ||
$response = Invoke-TeamViewerRestMethod ` | ||
-ApiToken $ApiToken ` | ||
-Uri $resourceUri ` | ||
-Method Get ` | ||
-Body $parameters ` | ||
-WriteErrorTo $PSCmdlet ` | ||
-ErrorAction Stop | ||
|
||
$parameters.paginationToken = $response.nextPaginationToken | ||
Write-Output ($response.resources | ConvertTo-TeamViewerManagedDevice) | ||
} while ($parameters.paginationToken) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- | ||
external help file: TeamViewerPS-help.xml | ||
Module Name: TeamViewerPS | ||
online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Get-TeamViewerCompanyManagedDevice.md | ||
schema: 2.0.0 | ||
--- | ||
|
||
# Get-TeamViewerCompanyManagedDevice | ||
|
||
## SYNOPSIS | ||
|
||
Retrieves TeamViewer company-managed devices. Requires an API Token with company admin permissions. | ||
|
||
## SYNTAX | ||
|
||
### List (Default) | ||
|
||
```powershell | ||
Get-TeamViewerCompanyManagedDevice -ApiToken <SecureString> [<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
Retrieves company-managed devices of the company that is associated with the API access token. | ||
|
||
## EXAMPLES | ||
|
||
### Example 1 | ||
|
||
```powershell | ||
PS /> Get-TeamViewerCompanyManagedDevice | ||
``` | ||
|
||
List all company-managed devices of this company. | ||
|
||
## PARAMETERS | ||
|
||
### -ApiToken | ||
|
||
The TeamViewer API access token. Needs to have company admin permissions to successfully retrieve the devices. | ||
|
||
```yaml | ||
Type: SecureString | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: True | ||
Position: Named | ||
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 | ||
## NOTES | ||
## RELATED LINKS | ||
[Get-TeamViewerManagedDevice](Get-TeamViewerManagedDevice.md) | ||
[Get-TeamViewerManagedGroup](Get-TeamViewerManagedGroup.md) | ||
[Get-TeamViewerManagementId](Get-TeamViewerManagementId.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
BeforeAll { | ||
. "$PSScriptRoot\..\..\Cmdlets\Public\Get-TeamViewerCompanyManagedDevice.ps1" | ||
|
||
@(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | ` | ||
ForEach-Object { . $_.FullName } | ||
|
||
$testApiToken = [securestring]@{} | ||
$null = $testApiToken | ||
|
||
Mock Get-TeamViewerApiUri { '//unit.test' } | ||
} | ||
|
||
Describe 'Get-TeamViewerCompanyManagedDevice' { | ||
Context 'AllDevices' { | ||
BeforeAll { | ||
Mock Invoke-TeamViewerRestMethod { @{ | ||
nextPaginationToken = $null | ||
resources = @( | ||
@{ id = 'ae222e9d-a665-4cea-85b7-d4a3a08a5e35'; name = 'test company-managed device 1' }, | ||
@{ id = '6cbfcfb2-a929-4987-a91b-89e2945412cf'; name = 'test company-managed device 2' }, | ||
@{ id = '99a87bed-3d60-46f2-a869-b7e67a6bf2c8'; name = 'test company-managed device 3' } | ||
) | ||
} } | ||
} | ||
|
||
It 'Should call the correct API endpoint to list company-managed devices' { | ||
Get-TeamViewerCompanyManagedDevice -ApiToken $testApiToken | ||
|
||
$base_test_path = '//unit.test' | ||
$desired_endpoint = 'managed/devices/company' | ||
|
||
Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { | ||
$ApiToken -eq $testApiToken -And ` | ||
$Uri -eq "$base_test_path/$desired_endpoint" -And ` | ||
$Method -eq 'Get' } | ||
} | ||
|
||
It 'Should return ManagedDevice objects' { | ||
$result = Get-TeamViewerCompanyManagedDevice -ApiToken $testApiToken | ||
$result | Should -HaveCount 3 | ||
$result[0].PSObject.TypeNames | Should -Contain 'TeamViewerPS.ManagedDevice' | ||
} | ||
|
||
It 'Should fetch consecutive pages' { | ||
Mock Invoke-TeamViewerRestMethod { @{ | ||
nextPaginationToken = 'abc' | ||
resources = @( | ||
@{ id = 'ae222e9d-a665-4cea-85b7-d4a3a08a5e35'; name = 'test company-managed device 1' }, | ||
@{ id = '6cbfcfb2-a929-4987-a91b-89e2945412cf'; name = 'test company-managed device 2' }, | ||
@{ id = '99a87bed-3d60-46f2-a869-b7e67a6bf2c8'; name = 'test company-managed device 3' } | ||
) | ||
} } | ||
Mock Invoke-TeamViewerRestMethod { @{ | ||
nextPaginationToken = $null | ||
resources = @( | ||
@{ id = '76e699b7-2559-4202-bf7b-c6af6929aa15'; name = 'test company-managed device 4' } | ||
) | ||
} } -ParameterFilter { $Body -And $Body['paginationToken'] -eq 'abc' } | ||
|
||
$result = Get-TeamViewerCompanyManagedDevice -ApiToken $testApiToken | ||
$result | Should -HaveCount 4 | ||
|
||
Assert-MockCalled Invoke-TeamViewerRestMethod -Times 2 -Scope It | ||
} | ||
} | ||
} |