From b956c09ead31ff422f1fa3600e80e25a6e7363d8 Mon Sep 17 00:00:00 2001 From: Maximilian Otter Date: Thu, 6 Oct 2022 10:03:54 +0200 Subject: [PATCH 1/7] Update Add-TeamViewerManager.ps1 included adding UserGroups as manager --- TeamViewerPS/Public/Add-TeamViewerManager.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/TeamViewerPS/Public/Add-TeamViewerManager.ps1 b/TeamViewerPS/Public/Add-TeamViewerManager.ps1 index d7f83bc..726ae16 100644 --- a/TeamViewerPS/Public/Add-TeamViewerManager.ps1 +++ b/TeamViewerPS/Public/Add-TeamViewerManager.ps1 @@ -23,9 +23,17 @@ function Add-TeamViewerManager { [object] $User, + [Parameter(Mandatory = $true, ParameterSetName = 'Group_ByUserGroupId')] + [Parameter(Mandatory = $true, ParameterSetName = 'Device_ByUserGroupId')] + [ValidateScript( { $_ | Resolve-TeamViewerUserGroupId })] + [Alias('UserGroupId')] + [object] + $UserGroup, + [Parameter(Mandatory = $true, ParameterSetName = 'Group_ByAccountId')] [Parameter(Mandatory = $true, ParameterSetName = 'Group_ByManagerId')] [Parameter(Mandatory = $true, ParameterSetName = 'Group_ByUserObject')] + [Parameter(Mandatory = $true, ParameterSetName = 'Group_ByUserGroupId')] [ValidateScript( { $_ | Resolve-TeamViewerManagedGroupId } )] [Alias("GroupId")] [object] @@ -34,6 +42,7 @@ function Add-TeamViewerManager { [Parameter(Mandatory = $true, ParameterSetName = 'Device_ByAccountId')] [Parameter(Mandatory = $true, ParameterSetName = 'Device_ByManagerId')] [Parameter(Mandatory = $true, ParameterSetName = 'Device_ByUserObject')] + [Parameter(Mandatory = $true, ParameterSetName = 'Device_ByUserGroupId')] [ValidateScript( { $_ | Resolve-TeamViewerManagedDeviceId } )] [Alias("DeviceId")] [object] @@ -70,6 +79,9 @@ function Add-TeamViewerManager { '*ByUserObject' { $body["accountId"] = $User.Id.TrimStart('u') } + '*ByUserGroupId' { + $body["usergroupId"] = $UserGroup | Resolve-TeamViewerUserGroupId + } } if ($Permissions) { From c70cd6cb1199f8feb171815ca7b2b12e0fe8fda4 Mon Sep 17 00:00:00 2001 From: Maximilian Otter Date: Mon, 10 Oct 2022 09:11:05 +0200 Subject: [PATCH 2/7] updated md-Help "Add-TeamViewerManager.md" --- docs/commands/Add-TeamViewerManager.md | 52 ++++++++++++++++++-------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/docs/commands/Add-TeamViewerManager.md b/docs/commands/Add-TeamViewerManager.md index 4f4b9cb..e3dddd2 100644 --- a/docs/commands/Add-TeamViewerManager.md +++ b/docs/commands/Add-TeamViewerManager.md @@ -14,47 +14,53 @@ Add a manager to a managed device or managed group. ## SYNTAX ### Device_ByAccountId (Default) - -```powershell +``` Add-TeamViewerManager -ApiToken -AccountId -Device [-Permissions ] [-WhatIf] [-Confirm] [] ``` ### Group_ByAccountId - -```powershell +``` Add-TeamViewerManager -ApiToken -AccountId -Group [-Permissions ] [-WhatIf] [-Confirm] [] ``` ### Group_ByManagerId - -```powershell +``` Add-TeamViewerManager -ApiToken -Manager -Group [-Permissions ] [-WhatIf] [-Confirm] [] ``` ### Device_ByManagerId - -```powershell +``` Add-TeamViewerManager -ApiToken -Manager -Device [-Permissions ] [-WhatIf] [-Confirm] [] ``` ### Group_ByUserObject - -```powershell +``` Add-TeamViewerManager -ApiToken -User -Group [-Permissions ] [-WhatIf] [-Confirm] [] ``` ### Device_ByUserObject - -```powershell +``` Add-TeamViewerManager -ApiToken -User -Device [-Permissions ] [-WhatIf] [-Confirm] [] ``` +### Device_ByUserGroupId +``` +Add-TeamViewerManager -ApiToken -UserGroup -Device [-Permissions ] + [-WhatIf] [-Confirm] [] +``` + +### Group_ByUserGroupId +``` +Add-TeamViewerManager -ApiToken -UserGroup -Group [-Permissions ] + [-WhatIf] [-Confirm] [] +``` + ## DESCRIPTION Adds a manager to a managed device or a managed group. Managers can either be @@ -82,7 +88,7 @@ PS /> Add-TeamViewerManager -Group '9fd16af0-c224-4242-998e-a7138b038dbb' -Manag Add the manager with the given Manager ID to the managed group with the given group ID. -### Example 2 +### Example 3 ```powershell PS /> Add-TeamViewerManager -Group '9fd16af0-c224-4242-998e-a7138b038dbb' -AccountId 1234 @@ -149,7 +155,7 @@ object that has been received using other module functions. ```yaml Type: Object -Parameter Sets: Device_ByAccountId, Device_ByManagerId, Device_ByUserObject +Parameter Sets: Device_ByAccountId, Device_ByManagerId, Device_ByUserObject, Device_ByUserGroupId Aliases: DeviceId Required: True @@ -167,7 +173,7 @@ object that has been received using other module functions. ```yaml Type: Object -Parameter Sets: Group_ByAccountId, Group_ByManagerId, Group_ByUserObject +Parameter Sets: Group_ByAccountId, Group_ByManagerId, Group_ByUserObject, Group_ByUserGroupId Aliases: GroupId Required: True @@ -248,6 +254,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -UserGroup +UserGroup object as returned from `Get-TeamViewerUserGroup` or Id of the UserGroup which should be added as manager of the targeted managed group or managed device. + +```yaml +Type: Object +Parameter Sets: Device_ByUserGroupId, Group_ByUserGroupId +Aliases: UserGroupId + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -WhatIf Shows what would happen if the cmdlet runs. @@ -266,7 +287,6 @@ 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 From d1d2d5006d32e5828456d3cb302ecf79062100e8 Mon Sep 17 00:00:00 2001 From: Maximilian Otter Date: Tue, 11 Oct 2022 15:17:35 +0200 Subject: [PATCH 3/7] bug fix line 80. $User is already ID --- TeamViewerPS/Public/Add-TeamViewerManager.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeamViewerPS/Public/Add-TeamViewerManager.ps1 b/TeamViewerPS/Public/Add-TeamViewerManager.ps1 index 726ae16..2a96adc 100644 --- a/TeamViewerPS/Public/Add-TeamViewerManager.ps1 +++ b/TeamViewerPS/Public/Add-TeamViewerManager.ps1 @@ -77,7 +77,7 @@ function Add-TeamViewerManager { $body["id"] = $Manager | Resolve-TeamViewerManagerId } '*ByUserObject' { - $body["accountId"] = $User.Id.TrimStart('u') + $body["accountId"] = $User.TrimStart('u') } '*ByUserGroupId' { $body["usergroupId"] = $UserGroup | Resolve-TeamViewerUserGroupId From 45c71a5d960832968125ea9674d84cd835f4a425 Mon Sep 17 00:00:00 2001 From: Maximilian Otter Date: Thu, 20 Oct 2022 10:03:14 +0200 Subject: [PATCH 4/7] Update Add-TeamViewerManager.ps1 --- TeamViewerPS/Public/Add-TeamViewerManager.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeamViewerPS/Public/Add-TeamViewerManager.ps1 b/TeamViewerPS/Public/Add-TeamViewerManager.ps1 index 2a96adc..bbec546 100644 --- a/TeamViewerPS/Public/Add-TeamViewerManager.ps1 +++ b/TeamViewerPS/Public/Add-TeamViewerManager.ps1 @@ -77,7 +77,7 @@ function Add-TeamViewerManager { $body["id"] = $Manager | Resolve-TeamViewerManagerId } '*ByUserObject' { - $body["accountId"] = $User.TrimStart('u') + $body["accountId"] = ( $User | Resolve-TeamViewerUserId ).TrimStart('u') } '*ByUserGroupId' { $body["usergroupId"] = $UserGroup | Resolve-TeamViewerUserGroupId From dc7d7766864d03165f01c74aea43585b0fd39073 Mon Sep 17 00:00:00 2001 From: Maximilian Otter Date: Mon, 24 Oct 2022 13:03:19 +0200 Subject: [PATCH 5/7] added Remove-TeamViewerUser --- TeamViewerPS/Public/Remove-TeamViewerUser.ps1 | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 TeamViewerPS/Public/Remove-TeamViewerUser.ps1 diff --git a/TeamViewerPS/Public/Remove-TeamViewerUser.ps1 b/TeamViewerPS/Public/Remove-TeamViewerUser.ps1 new file mode 100644 index 0000000..f88435b --- /dev/null +++ b/TeamViewerPS/Public/Remove-TeamViewerUser.ps1 @@ -0,0 +1,36 @@ +function Remove-TeamViewerUser { + [CmdletBinding(SupportsShouldProcess = $true)] + param( + [Parameter(Mandatory = $true)] + [securestring] + $ApiToken, + + [Parameter(Mandatory = $true, ValueFromPipeline = $true)] + [ValidateScript( { $_ | Resolve-TeamViewerUserId } )] + [Alias("UserId")] + [Alias("Id")] + [object] + $User, + + [Parameter()] + [switch] + $Permanent + ) + Process { + $userId = $User | Resolve-TeamViewerUserId + $resourceUri = "$(Get-TeamViewerApiUri)/users/$userId" + + if ($Permanent) { + $resourceUri += '?isPermanentDelete=true' + } + + if ($PSCmdlet.ShouldProcess($userId, "Remove user")) { + Invoke-TeamViewerRestMethod ` + -ApiToken $ApiToken ` + -Uri $resourceUri ` + -Method Delete ` + -WriteErrorTo $PSCmdlet | ` + Out-Null + } + } +} From ce38e6fb0a82ffcb3f89bb62bd48e3a4da218a58 Mon Sep 17 00:00:00 2001 From: Maximilian Otter Date: Mon, 24 Oct 2022 13:14:00 +0200 Subject: [PATCH 6/7] added test for Remove-TeamViewerUser --- Tests/Public/Remove-TeamViewerUser.Tests.ps1 | 57 ++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Tests/Public/Remove-TeamViewerUser.Tests.ps1 diff --git a/Tests/Public/Remove-TeamViewerUser.Tests.ps1 b/Tests/Public/Remove-TeamViewerUser.Tests.ps1 new file mode 100644 index 0000000..78f6038 --- /dev/null +++ b/Tests/Public/Remove-TeamViewerUser.Tests.ps1 @@ -0,0 +1,57 @@ +BeforeAll { + . "$PSScriptRoot/../../TeamViewerPS/Public/Remove-TeamViewerUser.ps1" + + @(Get-ChildItem -Path "$PSScriptRoot/../../TeamViewerPS/Private/*.ps1") | ` + ForEach-Object { . $_.FullName } + + $testApiToken = [securestring]@{} + $null = $testApiToken + + Mock Get-TeamViewerApiUri { '//unit.test' } + Mock Invoke-TeamViewerRestMethod { } +} + +Describe 'Remove-TeamViewerUser' { + It 'Should call the correct API endpoint' { + Remove-TeamViewerUser -ApiToken $testApiToken -User 'u1234' + + Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { + $ApiToken -eq $testApiToken -And ` + $Uri -eq '//unit.test/users/u1234' -And ` + $Method -eq 'Delete' } + } + + It 'Should accept group objects' { + $testUser = @{ id = 'u1234' } | ConvertTo-TeamViewerUser + Remove-TeamViewerUser -ApiToken $testApiToken -User $testUser + + Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { + $ApiToken -eq $testApiToken -And ` + $Uri -eq '//unit.test/users/u1234' -And ` + $Method -eq 'Delete' } + } + + It 'Should fail for invalid group identifiers' { + { Remove-TeamViewerUser -ApiToken $testApiToken -User 'invalid1234' } | Should -Throw + } + + It 'Should accept pipeline input' { + $testUser = @{ id = 'u1234' } | ConvertTo-TeamViewerUser + $testUser | Remove-TeamViewerUser -ApiToken $testApiToken + + Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { + $ApiToken -eq $testApiToken -And ` + $Uri -eq '//unit.test/users/u1234' -And ` + $Method -eq 'Delete' } + } + + It 'Should accept switch parameter "Permanent"' { + $testUser = @{ id = 'u1234' } | ConvertTo-TeamViewerUser + Remove-TeamViewerUser -ApiToken $testApiToken -User $testUser -Permanent + + Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter { + $ApiToken -eq $testApiToken -And ` + $Uri -eq '//unit.test/users/u1234?isPermanentDelete=true' -And ` + $Method -eq 'Delete' } + } +} From 2b0c9c835e95b0feb5103b5d63c98bbe68df3411 Mon Sep 17 00:00:00 2001 From: Maximilian Otter Date: Mon, 24 Oct 2022 13:33:58 +0200 Subject: [PATCH 7/7] aded mdhelp for Remove-TeamViewerUser --- docs/commands/Remove-TeamViewerUser.md | 131 +++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 docs/commands/Remove-TeamViewerUser.md diff --git a/docs/commands/Remove-TeamViewerUser.md b/docs/commands/Remove-TeamViewerUser.md new file mode 100644 index 0000000..e37553e --- /dev/null +++ b/docs/commands/Remove-TeamViewerUser.md @@ -0,0 +1,131 @@ +--- +external help file: TeamViewerPS-help.xml +Module Name: TeamViewerPS +online version: +schema: 2.0.0 +--- + +# Remove-TeamViewerUser + +## SYNOPSIS + +Removes a user from the TeamViewer tenant + +## SYNTAX + +``` +Remove-TeamViewerUser [-ApiToken] [-User] [-Permanent] [-WhatIf] [-Confirm] + [] +``` + +## DESCRIPTION + +Removes an existing user from the TeamViewer tenant. +If the switch -Permanent is added the user is delete from TeamViewer completely, otherwise it is only removed from the tenant. + +## EXAMPLES + +### Example 1 + +```powershell +PS C:\> Remove-TeamViewerUser -User 'u1234' +``` + + +## 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 +``` + +### -Permanent + +Deletes the user account completely instead of just removing it from the tenant. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -User + +Object that can be used to identify the user. +This can either be the user ID or a user object that has been received using other module functions + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: Id, UserId + +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