-
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 #13 from OtterKring/main
Update Add-TeamViewerManager.ps1
- Loading branch information
Showing
5 changed files
with
273 additions
and
17 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,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 | ||
} | ||
} | ||
} |
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,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' } | ||
} | ||
} |
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,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 |