Skip to content

Commit

Permalink
Merge pull request #56 from teamviewer/RemoveOldPermissions
Browse files Browse the repository at this point in the history
Remove old company permissions from user
  • Loading branch information
ChristianJ-TV authored Oct 14, 2023
2 parents 3776709 + 4877941 commit 9ad7088
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 236 deletions.
3 changes: 2 additions & 1 deletion .vscode/spelling
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// TeamViewerPS
// Project
TeamViewer
TeamViewer's
TeamViewerPS

// Powershell
cmdlet
Expand Down
68 changes: 36 additions & 32 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,76 @@

### Added

- Added 'Set-TeamViewerApiURi' to use TeamViewer test API.
- Added user role commands to remotely manage user roles of a TeamViewer company.
- Added `Add-TeamViewerAssignment` and `Remove-TeamViewerAssignment` commands to assign and unassign a device from a TeamViewer company.
- Added `Add-TeamViewerCustomization` and `Remove-TeamViewerCustomization` commands to apply and remove customization.
- Added `Export-TeamViewerSystemInformation` to create zip file for support.
- Added `Set-TeamViewerPSProxy` and `Remove-TeamViewerPSProxy` to set proxy to access WebAPI.
- Added `Get-TeamViewerInstallationDirectory` to return installation directory.
- Added `Remove-TeamViewerPolicyFromManagedDevice` to remove policies from managed devices.
- Adds user role commands to manage user roles of a TeamViewer company.
- Adds `Set-TeamViewerApiURi` to use TeamViewer test API.
- Adds `Add-TeamViewerAssignment` and `Remove-TeamViewerAssignment` commands to assign and unassign a device from a TeamViewer company.
- Adds `Add-TeamViewerCustomization` and `Remove-TeamViewerCustomization` commands to apply and remove customization.
- Adds `Export-TeamViewerSystemInformation` to create zip file for support.
- Adds `Set-TeamViewerPSProxy` and `Remove-TeamViewerPSProxy` to set proxy to access WebAPI.
- Adds `Get-TeamViewerInstallationDirectory` to return installation directory.
- Adds `Remove-TeamViewerPolicyFromManagedDevice` to remove policies from managed devices.

### Changed

- Extended `Invoke-TeamViewerPackageDownload` with MSI package type.
- Folder structure modified.
- `-RemovePolicy` switch removed from `Set-TeamViewerManagedDevice`.
- Extends `Invoke-TeamViewerPackageDownload` with MSI package type.
- Modifies general folder structure.
- Removes `-RemovePolicy` switch from `Set-TeamViewerManagedDevice`.

### Fixed

- Fixed `Get-TeamViewerLinuxGlobalConfig` to handle null values.
- Fixes `Get-TeamViewerLinuxGlobalConfig` to handle null values.

## 1.5.2 (2023-09-18)

- Remove-TeamViewerPolicyFromManagedDevice has been added.
- ManagedGroupId parameter has been added to Set-TeamViewerManagedDevice.
### Added

- Adds `Remove-TeamViewerPolicyFromManagedDevice` to remove a policy from a managed device.

### Changed

- Adds `ManagedGroupId` parameter to `Set-TeamViewerManagedDevice`.

## 1.5.1 (2023-07-18)

- Improved `User ID` parameter handling for `Add-TeamViewerUserGroupMember` and `Remove-TeamViewerUserGroupMember`
- Improves `User ID` parameter handling for `Add-TeamViewerUserGroupMember` and `Remove-TeamViewerUserGroupMember`.

## 1.5.0 (2023-05-24)

### Added

- Added `Remove-TeamViewerUser` cmdlet to remove user from TeamViewer company. (Thanks @OtterKring)
- Added `Remove-TeamViewerManagedDeviceManagement` to unmanage a device.
- Adds `Remove-TeamViewerUser` cmdlet to remove user from TeamViewer company. (Thanks @OtterKring)
- Adds `Remove-TeamViewerManagedDeviceManagement` to un-manage a device.

### Changed

- Extended `Add-TeamViewerManager` to add user group as manager. (Thanks @OtterKring)
- Extended `TeamViewerManagedDevice` to have "LastSeenAt" available for managed devices
- Extends `Add-TeamViewerManager` to add user group as manager. (Thanks @OtterKring)
- Adds `LastSeenAt` to `TeamViewerManagedDevice` for managed devices.

## 1.4.0 (2022-04-19)

### Fixed
### Added

- Fixed `-Group` parameter of `Remove-TeamViewerManagedDevice` to be mandatory.
- Adds `Get-TeamViewerConnectionReport` cmdlet to fetch TeamViewer session / connection reports.

### Added
### Fixed

- Added `Get-TeamViewerConnectionReport` cmdlet to fetch TeamViewer session/connection reports.
- Fixes `-Group` parameter of `Remove-TeamViewerManagedDevice` to be mandatory.

## 1.3.1 (2021-11)

### Fixed
### Changed

- Fixed `Set-TeamViewerPolicy` to support changing policy settings.
- `Get-TeamViewerUser` includes license information.

### Changed
### Fixed

- Result of `Get-TeamViewerUser` now also includes license information.
- Fixes `Set-TeamViewerPolicy` to support changing policy settings.

## 1.3.0 (2021-11-29)

### Added

- Adds command `Get-TeamViewerEventLog` to fetch event log entries.
- Adds `Get-TeamViewerEventLog` to fetch event log entries.
- Adds user group commands to remotely manage user groups of a TeamViewer company.

## 1.2.0 (2021-07-19)
Expand All @@ -77,8 +82,7 @@

- Adds command `Set-TeamViewerManagedDevice` to change properties of a managed device.
- Adds optional `Policy` property to `Get-TeamViewerManagedDevice` result entries.
- Adds `-Device` parameter to `Get-TeamViewerManagedGroup` command, allowing to
fetch all managed groups that a particular device is part of.
- Adds `-Device` parameter to `Get-TeamViewerManagedGroup` command, allowing to fetch all managed groups that a particular device is part of.

## 1.1.0 (2021-04-15)

Expand All @@ -89,8 +93,8 @@

### Changed

- Improved bulk support for `Add-TeamViewerSsoExclusion` and `Remove-TeamViewerSsoExclusion`.
- Improves bulk support for `Add-TeamViewerSsoExclusion` and `Remove-TeamViewerSsoExclusion`.

## 1.0.0 (2021-01-15)

- Initial release of TeamViewerPS
- Initial release of TeamViewerPS
9 changes: 7 additions & 2 deletions Cmdlets/Private/ConvertTo-TeamViewerUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,41 @@ function ConvertTo-TeamViewerUser {
[ValidateSet('All', 'Minimal')]
$PropertiesToLoad = 'All'
)

process {
$properties = @{
Id = $InputObject.id
Name = $InputObject.name
Email = $InputObject.email
}

if ($PropertiesToLoad -Eq 'All') {
$properties += @{
Permissions = $InputObject.permissions -split ','
Active = $InputObject.active
LastAccessDate = $InputObject.last_access_date | ConvertTo-DateTime
}

if ($InputObject.activated_license_id) {
$properties += @{
ActivatedLicenseId = [guid]$InputObject.activated_license_id
ActivatedLicenseName = $InputObject.activated_license_name
ActivatedSubLicenseName = $InputObject.activated_subLicense_name
}
}

if ($InputObject.activated_meeting_license_key) {
$properties += @{
ActivatedMeetingLicenseId = [guid]$InputObject.activated_meeting_license_key
}
}
}

$result = New-Object -TypeName PSObject -Property $properties
$result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.User')
$result | Add-Member -MemberType ScriptMethod -Name "ToString" -Force -Value {
$result | Add-Member -MemberType ScriptMethod -Name 'ToString' -Force -Value {
Write-Output "$($this.Name) <$($this.Email)>"
}

Write-Output $result
}
}
44 changes: 18 additions & 26 deletions Cmdlets/Public/Get-TeamViewerUser.ps1
Original file line number Diff line number Diff line change
@@ -1,69 +1,61 @@
function Get-TeamViewerUser {
[CmdletBinding(DefaultParameterSetName = "FilteredList")]
[CmdletBinding(DefaultParameterSetName = 'FilteredList')]
param(
[Parameter(Mandatory = $true)]
[securestring]
$ApiToken,

[Parameter(ParameterSetName = "ByUserId")]
[Parameter(ParameterSetName = 'ByUserId')]
[ValidateScript( { $_ | Resolve-TeamViewerUserId } )]
[Alias("UserId")]
[Alias('UserId')]
[string]
$Id,

[Parameter(ParameterSetName = "FilteredList")]
[Alias("PartialName")]
[Parameter(ParameterSetName = 'FilteredList')]
[Alias('PartialName')]
[string]
$Name,

[Parameter(ParameterSetName = "FilteredList")]
[Parameter(ParameterSetName = 'FilteredList')]
[string[]]
$Email,

[Parameter(ParameterSetName = "FilteredList")]
[string[]]
$Permissions,

[Parameter()]
[ValidateSet("All", "Minimal")]
$PropertiesToLoad = "All"
[ValidateSet('All', 'Minimal')]
$PropertiesToLoad = 'All'
)

$parameters = @{ }
switch ($PropertiesToLoad) {
"All" { $parameters.full_list = $true }
"Minimal" { }
'All' {
$parameters.full_list = $true
}
'Minimal' {
}
}

$resourceUri = "$(Get-TeamViewerApiUri)/users"

switch ($PsCmdlet.ParameterSetName) {
"ByUserId" {
'ByUserId' {
$resourceUri += "/$Id"
$parameters = $null
}
"FilteredList" {
'FilteredList' {
if ($Name) {
$parameters['name'] = $Name
}

if ($Email) {
$parameters['email'] = ($Email -join ',')
}
if ($Permissions) {
$parameters['permissions'] = ($Permissions -join ',')
}
}
}

$response = Invoke-TeamViewerRestMethod `
-ApiToken $ApiToken `
-Uri $resourceUri `
-Method Get `
-Body $parameters `
-WriteErrorTo $PSCmdlet `
-ErrorAction Stop
-ApiToken $ApiToken -Uri $resourceUri -Method Get -Body $parameters -WriteErrorTo $PSCmdlet -ErrorAction Stop

if ($PsCmdlet.ParameterSetName -Eq "ByUserId") {
if ($PsCmdlet.ParameterSetName -Eq 'ByUserId') {
Write-Output ($response | ConvertTo-TeamViewerUser -PropertiesToLoad $PropertiesToLoad)
}
else {
Expand Down
39 changes: 16 additions & 23 deletions Cmdlets/Public/New-TeamViewerUser.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function New-TeamViewerUser {
[CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName = "WithPassword")]
[CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName = 'WithPassword')]
param(
[Parameter(Mandatory = $true)]
[securestring]
Expand All @@ -15,11 +15,11 @@ function New-TeamViewerUser {
[string]
$Name,

[Parameter(Mandatory = $true, ParameterSetName = "WithPassword")]
[Parameter(Mandatory = $true, ParameterSetName = 'WithPassword')]
[securestring]
$Password,

[Parameter(ParameterSetName = "WithoutPassword")]
[Parameter(ParameterSetName = 'WithoutPassword')]
[Alias('NoPassword')]
[switch]
$WithoutPassword,
Expand All @@ -28,26 +28,25 @@ function New-TeamViewerUser {
[securestring]
$SsoCustomerIdentifier,

[Parameter()]
[array]
$Permissions,

[Parameter()]
[ValidateScript( { $_ | Resolve-TeamViewerLanguage } )]
[cultureinfo]
$Culture
)

if (-Not $Culture) {
try { $Culture = Get-Culture }
catch { $Culture = 'en' }
try {
$Culture = Get-Culture
}
catch {
$Culture = 'en'
}
}

$body = @{
email = $Email
name = $Name
language = $Culture | Resolve-TeamViewerLanguage
permissions = $Permissions -join ','
email = $Email
name = $Name
language = $Culture | Resolve-TeamViewerLanguage
}

if ($Password -And -Not $WithoutPassword) {
Expand All @@ -63,18 +62,12 @@ function New-TeamViewerUser {
}

$resourceUri = "$(Get-TeamViewerApiUri)/users"
if ($PSCmdlet.ShouldProcess("$Name <$Email>", "Create user")) {
$response = Invoke-TeamViewerRestMethod `
-ApiToken $ApiToken `
-Uri $resourceUri `
-Method Post `
-ContentType "application/json; charset=utf-8" `
-Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) `
-WriteErrorTo $PSCmdlet `
-ErrorAction Stop

if ($PSCmdlet.ShouldProcess("$Name <$Email>", 'Create user')) {
$response = Invoke-TeamViewerRestMethod -ApiToken $ApiToken -Uri $resourceUri -Method Post -ContentType 'application/json; charset=utf-8' `
-Body ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json))) -WriteErrorTo $PSCmdlet -ErrorAction Stop
$result = ($response | ConvertTo-TeamViewerUser)
$result.Email = $Email

Write-Output $result
}
}
Loading

0 comments on commit 9ad7088

Please sign in to comment.