-
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.
allow unmanage of Devices, add LastSeen field to managed devices (#17)
Add new field "LastSeenAt" to devices fetched via API Add new function "Remove-TeamViewerManagedDeviceManagement" to allow unmanaging of devices
- Loading branch information
1 parent
4ed3b97
commit 46dab6d
Showing
9 changed files
with
209 additions
and
11 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
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
28 changes: 28 additions & 0 deletions
28
TeamViewerPS/Public/Remove-TeamViewerManagedDeviceManagement.ps1
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,28 @@ | ||
function Remove-TeamViewerManagedDeviceManagement { | ||
[CmdletBinding(SupportsShouldProcess = $true)] | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[securestring] | ||
$ApiToken, | ||
|
||
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | ||
[ValidateScript( { $_ | Resolve-TeamViewerManagedDeviceId } )] | ||
[Alias('DeviceId')] | ||
[object] | ||
$Device | ||
) | ||
Process { | ||
$deviceId = $Device | Resolve-TeamViewerManagedDeviceId | ||
|
||
$resourceUri = "$(Get-TeamViewerApiUri)/managed/devices/$deviceId" | ||
|
||
if ($PSCmdlet.ShouldProcess($deviceId, 'Remove Management from a device (clears all managers and groups)')) { | ||
Invoke-TeamViewerRestMethod ` | ||
-ApiToken $ApiToken ` | ||
-Uri $resourceUri ` | ||
-Method Delete ` | ||
-WriteErrorTo $PSCmdlet | ` | ||
Out-Null | ||
} | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
Tests/Public/Remove-TeamViewerManagedDeviceManagement.Tests.ps1
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,45 @@ | ||
BeforeAll { | ||
. "$PSScriptRoot/../../TeamViewerPS/Public/Remove-TeamViewerManagedDeviceManagement.ps1" | ||
|
||
@(Get-ChildItem -Path "$PSScriptRoot/../../TeamViewerPS/Private/*.ps1") | ` | ||
ForEach-Object { . $_.FullName } | ||
|
||
$testApiToken = [securestring]@{} | ||
$null = $testApiToken | ||
$testDeviceId = 'c37e72b8-b78d-467f-923c-6083c13cf82f' | ||
$null = $testDeviceId | ||
|
||
Mock Get-TeamViewerApiUri { '//unit.test' } | ||
Mock Invoke-TeamViewerRestMethod { } | ||
} | ||
|
||
Describe 'Remove-TeamViewerManagedDeviceManagement' { | ||
It 'Should call the correct API endpoint' { | ||
Remove-TeamViewerManagedDeviceManagement -ApiToken $testApiToken -DeviceId $testDeviceId | ||
|
||
Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { | ||
$ApiToken -eq $testApiToken -And ` | ||
$Uri -eq "//unit.test/managed/devices/$testDeviceId" -And ` | ||
$Method -eq 'Delete' } | ||
} | ||
|
||
It 'Should accept ManagedDevice objects' { | ||
$testDeviceObj = @{ id = $testDeviceId } | ConvertTo-TeamViewerManagedDevice | ||
Remove-TeamViewerManagedDeviceManagement -ApiToken $testApiToken -Device $testDeviceObj | ||
|
||
Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { | ||
$ApiToken -eq $testApiToken -And ` | ||
$Uri -eq "//unit.test/managed/devices/$testDeviceId" -And ` | ||
$Method -eq 'Delete' } | ||
} | ||
|
||
It 'Should accept pipeline input' { | ||
$testDeviceObj = @{ id = $testDeviceId } | ConvertTo-TeamViewerManagedDevice | ||
$testDeviceObj | Remove-TeamViewerManagedDeviceManagement -ApiToken $testApiToken | ||
|
||
Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { | ||
$ApiToken -eq $testApiToken -And ` | ||
$Uri -eq "//unit.test/managed/devices/$testDeviceId" -And ` | ||
$Method -eq 'Delete' } | ||
} | ||
} |
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
116 changes: 116 additions & 0 deletions
116
docs/commands/Remove-TeamViewerManagedDeviceManagement.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
--- | ||
external help file: TeamViewerPS-help.xml | ||
Module Name: TeamViewerPS | ||
online version: https://github.com/teamviewer/TeamViewerPS/blob/main/docs/commands/Remove-TeamViewerManagedDeviceManagement.md | ||
schema: 2.0.0 | ||
--- | ||
|
||
# Remove-TeamViewerManagedDevice | ||
|
||
## SYNOPSIS | ||
|
||
Removes the management status from a managed device. | ||
|
||
## SYNTAX | ||
|
||
```powershell | ||
Remove-TeamViewerManagedDeviceManagement [-ApiToken] <SecureString> [-Device] <Object> [-WhatIf] | ||
[-Confirm] [<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
Removes the management status from a managed device. | ||
This makes the device unmanaged removing it from all groups and removing all managers. | ||
The current account needs `ManagerAdministration` manager permissions on the device. | ||
|
||
## EXAMPLES | ||
|
||
### Example 1 | ||
|
||
```powershell | ||
PS /> Remove-TeamViewerManagedDeviceManagement -Device 'c0cb303a-8a85-4e54-b657-a4757c791aef' | ||
``` | ||
|
||
## 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 | ||
``` | ||
### -Confirm | ||
Prompts you for confirmation before running the cmdlet. | ||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
Aliases: cf | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -Device | ||
Object that can be used to identify the managed device. | ||
This can either be the managed device ID (as string or GUID) or a managed device | ||
object that has been received using other module functions. | ||
```yaml | ||
Type: Object | ||
Parameter Sets: (All) | ||
Aliases: DeviceId | ||
|
||
Required: True | ||
Position: 1 | ||
Default value: None | ||
Accept pipeline input: True (ByValue) | ||
Accept wildcard characters: False | ||
``` | ||
### -WhatIf | ||
Shows what would happen if the cmdlet runs. | ||
The cmdlet is not run. | ||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
Aliases: wi | ||
|
||
Required: False | ||
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 | ||
### System.Object | ||
## OUTPUTS | ||
## NOTES | ||
## RELATED LINKS |