Skip to content

Commit

Permalink
Merge pull request #13 from OtterKring/main
Browse files Browse the repository at this point in the history
Update Add-TeamViewerManager.ps1
  • Loading branch information
ChristianJ-TV authored Apr 25, 2023
2 parents bcce2d4 + 2b0c9c8 commit 4d41a1f
Show file tree
Hide file tree
Showing 5 changed files with 273 additions and 17 deletions.
14 changes: 13 additions & 1 deletion TeamViewerPS/Public/Add-TeamViewerManager.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -68,7 +77,10 @@ function Add-TeamViewerManager {
$body["id"] = $Manager | Resolve-TeamViewerManagerId
}
'*ByUserObject' {
$body["accountId"] = $User.Id.TrimStart('u')
$body["accountId"] = ( $User | Resolve-TeamViewerUserId ).TrimStart('u')
}
'*ByUserGroupId' {
$body["usergroupId"] = $UserGroup | Resolve-TeamViewerUserGroupId
}
}

Expand Down
36 changes: 36 additions & 0 deletions TeamViewerPS/Public/Remove-TeamViewerUser.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}
}
57 changes: 57 additions & 0 deletions Tests/Public/Remove-TeamViewerUser.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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' }
}
}
52 changes: 36 additions & 16 deletions docs/commands/Add-TeamViewerManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,53 @@ Add a manager to a managed device or managed group.
## SYNTAX

### Device_ByAccountId (Default)

```powershell
```
Add-TeamViewerManager -ApiToken <SecureString> -AccountId <String> -Device <Object> [-Permissions <String[]>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

### Group_ByAccountId

```powershell
```
Add-TeamViewerManager -ApiToken <SecureString> -AccountId <String> -Group <Object> [-Permissions <String[]>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

### Group_ByManagerId

```powershell
```
Add-TeamViewerManager -ApiToken <SecureString> -Manager <Object> -Group <Object> [-Permissions <String[]>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

### Device_ByManagerId

```powershell
```
Add-TeamViewerManager -ApiToken <SecureString> -Manager <Object> -Device <Object> [-Permissions <String[]>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

### Group_ByUserObject

```powershell
```
Add-TeamViewerManager -ApiToken <SecureString> -User <Object> -Group <Object> [-Permissions <String[]>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

### Device_ByUserObject

```powershell
```
Add-TeamViewerManager -ApiToken <SecureString> -User <Object> -Device <Object> [-Permissions <String[]>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

### Device_ByUserGroupId
```
Add-TeamViewerManager -ApiToken <SecureString> -UserGroup <Object> -Device <Object> [-Permissions <String[]>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

### Group_ByUserGroupId
```
Add-TeamViewerManager -ApiToken <SecureString> -UserGroup <Object> -Group <Object> [-Permissions <String[]>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION

Adds a manager to a managed device or a managed group. Managers can either be
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
131 changes: 131 additions & 0 deletions docs/commands/Remove-TeamViewerUser.md
Original file line number Diff line number Diff line change
@@ -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] <SecureString> [-User] <Object> [-Permanent] [-WhatIf] [-Confirm]
[<CommonParameters>]
```

## 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

0 comments on commit 4d41a1f

Please sign in to comment.