-
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 #29 from AlexandrosAlexiou/Enrich-Managed-Devices-…
…Policy-Management Add policy management capabilities for managed devices
- Loading branch information
Showing
7 changed files
with
322 additions
and
2 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
TeamViewerPS/Public/Remove-TeamViewerPolicyFromManagedDevice.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,39 @@ | ||
function Remove-TeamviewerPolicyFromManagedDevice { | ||
[CmdletBinding(SupportsShouldProcess = $true)] | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[securestring] | ||
$ApiToken, | ||
|
||
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | ||
[ValidateScript( { $_ | Resolve-TeamViewerManagedDeviceId } )] | ||
[Alias("DeviceId")] | ||
[object] | ||
$Device, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[PolicyType] | ||
$PolicyType | ||
) | ||
Begin { | ||
$body = @{ | ||
'policy_type' = [int]$PolicyType | ||
} | ||
} | ||
Process { | ||
$deviceId = $Device | Resolve-TeamViewerManagedDeviceId | ||
$resourceUri = "$(Get-TeamViewerApiUri)/managed/devices/$deviceId/policy/remove" | ||
|
||
if ($PSCmdlet.ShouldProcess($Device.ToString(), "Change managed device entry")) { | ||
Invoke-TeamViewerRestMethod ` | ||
-ApiToken $ApiToken ` | ||
-Uri $resourceUri ` | ||
-Method Put ` | ||
-ContentType "application/json; charset=utf-8" ` | ||
-Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) ` | ||
-WriteErrorTo $PSCmdlet ` | ||
-ErrorAction Stop | ` | ||
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
55 changes: 55 additions & 0 deletions
55
Tests/Public/Remove-TeamViewerPolicyFromManagedDevice.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,55 @@ | ||
BeforeAll { | ||
. "$PSScriptRoot/../../TeamViewerPS/Public/Remove-TeamViewerPolicyFromManagedDevice.ps1" | ||
. "$PSScriptRoot/../../TeamViewerPS/TeamViewerPS.Types.ps1" | ||
|
||
@(Get-ChildItem -Path "$PSScriptRoot/../../TeamViewerPS/Private/*.ps1") | ` | ||
ForEach-Object { . $_.FullName } | ||
|
||
$testApiToken = [securestring]@{} | ||
$null = $testApiToken | ||
$testDeviceId = '9e5617cb-2b20-4da2-bca4-c1bda85b29ab' | ||
$null = $testDeviceId | ||
|
||
Mock Get-TeamViewerApiUri { '//unit.test' } | ||
$mockArgs = @{} | ||
Mock Invoke-TeamViewerRestMethod { $mockArgs.Body = $Body } | ||
} | ||
|
||
Describe 'Remove-TeamViewerPolicyFromManagedDevice' { | ||
|
||
It 'Should call the correct API endpoint to remove a policy from the managed device' { | ||
Remove-TeamViewerPolicyFromManagedDevice -ApiToken $testApiToken -Device $testDeviceId -PolicyType TeamViewer | ||
Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { | ||
$ApiToken -eq $testApiToken -And ` | ||
$Uri -eq "//unit.test/managed/devices/$testDeviceId/policy/remove" -And ` | ||
$Method -eq 'Put' } | ||
} | ||
|
||
It 'should remove teamviewer policy from managed device' { | ||
Remove-TeamViewerPolicyFromManagedDevice -apitoken $testapitoken -device $testdeviceid -Policytype TeamViewer | ||
$mockargs.body | Should -Not -BeNullOrEmpty | ||
$body = [system.text.encoding]::utf8.getstring($mockargs.body) | ConvertFrom-Json | ||
$body.policy_type | Should -Be 1 | ||
} | ||
|
||
It 'should remove monitoring policy from managed device' { | ||
Remove-TeamViewerPolicyFromManagedDevice -apitoken $testapitoken -device $testdeviceid -PolicyType Monitoring | ||
$mockargs.body | Should -Not -BeNullOrEmpty | ||
$body = [system.text.encoding]::utf8.getstring($mockargs.body) | ConvertFrom-Json | ||
$body.policy_type | Should -Be 4 | ||
} | ||
|
||
It 'should remove patch management policy from managed device' { | ||
Remove-TeamViewerPolicyFromManagedDevice -apitoken $testapitoken -device $testdeviceid -PolicyType PatchManagement | ||
$mockargs.body | Should -Not -BeNullOrEmpty | ||
$body = [system.text.encoding]::utf8.getstring($mockargs.body) | ConvertFrom-Json | ||
$body.policy_type | Should -Be 5 | ||
} | ||
|
||
It 'Should throw an error when called with invalid policy type' { | ||
{ Remove-TeamViewerPolicyFromManagedDevice ` | ||
-ApiToken $testApiToken ` | ||
-Device $testDeviceId -PolicyType 2 } | Should -Throw | ||
} | ||
} | ||
|
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
157 changes: 157 additions & 0 deletions
157
docs/commands/Remove-TeamViewerPolicyFromManagedDevice.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,157 @@ | ||
--- | ||
external help file: TeamViewerPS-help.xml | ||
Module Name: TeamViewerPS | ||
online version: [Link to Online Documentation] | ||
schema: 2.0.0 | ||
--- | ||
|
||
# Remove-TeamViewerPolicyFromManagedDevice | ||
|
||
## SYNOPSIS | ||
|
||
Remove a policy from a managed device based on type. | ||
|
||
Valid Types are: | ||
|
||
- TeamViewer | ||
- Monitoring | ||
- PatchManagement | ||
|
||
## SYNTAX | ||
|
||
```powershell | ||
Remove-TeamViewerPolicyFromManagedDevice -ApiToken <SecureString> -Device <Object> -PolicyType <PolicyType> [-WhatIf] [-Confirm] [<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
Remove a specified policy from a managed device. | ||
|
||
## EXAMPLES | ||
|
||
### Example 1 | ||
|
||
Remove TeamViewer policy from device | ||
|
||
```powershell | ||
PS /> Remove-TeamViewerPolicyFromManagedDevice -Device 'd8773208-a685-4323-9de5-7f86951f8c30' -PolicyType 1 | ||
``` | ||
|
||
```powershell | ||
PS /> Remove-TeamViewerPolicyFromManagedDevice -Device 'd8773208-a685-4323-9de5-7f86951f8c30' -PolicyType TeamViewer | ||
``` | ||
|
||
### Example 2 | ||
|
||
Remove Monitoring policy from device | ||
|
||
```powershell | ||
PS /> Remove-TeamViewerPolicyFromManagedDevice -Device '730ee15a-1ea4-4d80-9cfe-5a01709d0a2f' -PolicyType 4 | ||
``` | ||
|
||
```powershell | ||
PS /> Remove-TeamViewerPolicyFromManagedDevice -Device '730ee15a-1ea4-4d80-9cfe-5a01709d0a2f' -PolicyType Monitoring | ||
``` | ||
|
||
### Example 3 | ||
|
||
Remove PatchManagement policy from device | ||
|
||
```powershell | ||
PS /> Remove-TeamViewerPolicyFromManagedDevice -Device '730ee15a-1ea4-4d80-9cfe-5a01709d0a2f' -PolicyType 5 | ||
``` | ||
|
||
```powershell | ||
PS /> Remove-TeamViewerPolicyFromManagedDevice -Device '730ee15a-1ea4-4d80-9cfe-5a01709d0a2f' -PolicyType PatchManagement | ||
``` | ||
|
||
## 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 | ||
``` | ||
### -Device | ||
The managed device from which you want to remove the policy. | ||
```yaml | ||
Type: Object | ||
Parameter Sets: (All) | ||
Aliases: DeviceId | ||
Required: True | ||
Position: 1 | ||
Default value: None | ||
Accept pipeline input: True (ByValue) | ||
Accept wildcard characters: False | ||
``` | ||
### -PolicyType | ||
The type of policy to remove from the managed device. | ||
```yaml | ||
Type: PolicyType (Enum) | ||
Parameter Sets: (All) | ||
Aliases: | ||
Required: True | ||
Position: 2 | ||
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 | ||
``` | ||
### -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 |
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