diff --git a/Cmdlets/Private/ConvertTo-TeamViewerUser.ps1 b/Cmdlets/Private/ConvertTo-TeamViewerUser.ps1 index 988ff4a..653e492 100644 --- a/Cmdlets/Private/ConvertTo-TeamViewerUser.ps1 +++ b/Cmdlets/Private/ConvertTo-TeamViewerUser.ps1 @@ -15,6 +15,11 @@ function ConvertTo-TeamViewerUser { Name = $InputObject.name Email = $InputObject.email } + if ($InputObject.userRoleId) { + $properties += @{ + RoleId = $InputObject.userRoleId + } + } if ($PropertiesToLoad -Eq 'All') { $properties += @{ diff --git a/Cmdlets/Public/New-TeamViewerUser.ps1 b/Cmdlets/Public/New-TeamViewerUser.ps1 index 2381fe0..ab1750d 100644 --- a/Cmdlets/Public/New-TeamViewerUser.ps1 +++ b/Cmdlets/Public/New-TeamViewerUser.ps1 @@ -31,15 +31,24 @@ function New-TeamViewerUser { [Parameter()] [ValidateScript( { $_ | Resolve-TeamViewerLanguage } )] [cultureinfo] - $Culture + $Culture, + + [Parameter()] + [ValidateScript({ $_ | Resolve-TeamViewerRoleId })] + [object] + $RoleId, + + [Parameter()] + [switch] + $IgnorePredefinedRole ) if (-Not $Culture) { try { - $Culture = Get-Culture + $Culture = Get-Culture } catch { - $Culture = 'en' + $Culture = 'en' } } @@ -61,6 +70,14 @@ function New-TeamViewerUser { [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr) | Out-Null } + if($RoleId){ + $body['userRoleId'] = $RoleId | Resolve-TeamViewerRoleId + } + + if($IgnorePredefinedRole){ + $body['ignorePredefinedRole'] = $true + } + $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' ` diff --git a/Cmdlets/Public/Set-TeamViewerUser.ps1 b/Cmdlets/Public/Set-TeamViewerUser.ps1 index 835b905..dcda9d7 100644 --- a/Cmdlets/Public/Set-TeamViewerUser.ps1 +++ b/Cmdlets/Public/Set-TeamViewerUser.ps1 @@ -36,7 +36,19 @@ function Set-TeamViewerUser { [Parameter(Mandatory = $true, ParameterSetName = 'ByProperties')] [hashtable] - $Property + $Property, + + [Parameter()] + [Alias('AssignRole')] + [ValidateScript({ $_ | Resolve-TeamViewerRoleId })] + [string[]] + $AssignRoleId, + + [Parameter()] + [Alias('UnassignRole')] + [ValidateScript({ $_ | Resolve-TeamViewerRoleId })] + [string[]] + $UnassignRoleId ) $body = @{} @@ -61,6 +73,12 @@ function Set-TeamViewerUser { $body['sso_customer_id'] = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr) [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr) | Out-Null } + if($AssignRoleId){ + $body['assignUserRoleIds'] = @($AssignRoleId) + } + if($UnassignRoleId){ + $body['unassignUserRoleIds'] = @($UnassignRoleId) + } } 'ByProperties' { @('active', 'email', 'name', 'password', 'sso_customer_id') | Where-Object { $Property[$_] } | ForEach-Object { $body[$_] = $Property[$_] } diff --git a/Docs/Help/New-TeamViewerUser.md b/Docs/Help/New-TeamViewerUser.md index 0125200..4d5230e 100644 --- a/Docs/Help/New-TeamViewerUser.md +++ b/Docs/Help/New-TeamViewerUser.md @@ -16,14 +16,14 @@ Create a new TeamViewer company user. ### WithPassword (Default) ```powershell -New-TeamViewerUser -ApiToken -Email -Name -Password +New-TeamViewerUser -ApiToken -Email -Name -Password [-RoleId ][-IgnorePredefinedRole ] [-SsoCustomerIdentifier ] [-Culture ] [-WhatIf] [-Confirm] [] ``` ### WithoutPassword ```powershell -New-TeamViewerUser -ApiToken -Email -Name [-WithoutPassword] +New-TeamViewerUser -ApiToken -Email -Name [-WithoutPassword][-IgnorePredefinedRole ] [-SsoCustomerIdentifier ] [-Culture ] [-WhatIf] [-Confirm] [] ``` @@ -50,6 +50,15 @@ PS /> New-TeamViewerUser -Email 'test@example.test' -Name 'Test User' -WithoutPa Create a new user with the given email address and name. It will be created without a password. The user must reset the password through the TeamViewer web page. +### Example 3 + +```powershell +PS /> New-TeamViewerUser -Email 'test@example.test' -Name 'Test User' -RoleId '9b465ea2-2f75-4101-a057-58a81ed0e57b' +``` + +Create a new user with the given email address and name. +The Role with RoleID `9b465ea2-2f75-4101-a057-58a81ed0e57b` will be assigned. + ## PARAMETERS ### -ApiToken @@ -166,6 +175,22 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -RoleId + +Role assigned to the user. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: None + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -WhatIf Shows what would happen if the cmdlet runs. diff --git a/Docs/Help/Set-TeamViewerUser.md b/Docs/Help/Set-TeamViewerUser.md index 4d359ba..083b7ee 100644 --- a/Docs/Help/Set-TeamViewerUser.md +++ b/Docs/Help/Set-TeamViewerUser.md @@ -16,7 +16,7 @@ Change properties of a TeamViewer company user. ### ByParameters (Default) ```powershell -Set-TeamViewerUser -ApiToken -User [-Active ] [-Email ] +Set-TeamViewerUser -ApiToken -User [-Active ] [-Email ][-AssignRoleId ][-UnassignRoleId ] [-Name ] [-Password ] [-SsoCustomerIdentifier ] [-WhatIf] [-Confirm] [] ``` @@ -66,6 +66,15 @@ PS /> Set-TeamViewerUser -UserId 'u1234' -SsoCustomerIdentifier $ssoCustomerIden Do the SSO activation step for the given user. This can also be used to repair a possibly broken SSO login token for that user. +### Example 5 + +```powershell +PS /> Set-TeamViewerUser -User 'u1234' -Name 'New user name' -AssignRoleId 'dd1cb784-bd1e-4056-a60b-3764ffe69e35' +-UnassignRoleId 'a6776890-d687-4c70-b180-9b563f15d1ab' +``` + +Assign and unassign Roles of the user `u1234` + ## PARAMETERS ### -Active @@ -164,6 +173,38 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -AssignRoleId + +Role assigned to the user. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: AssignRole + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UnassignRoleId + +Role unassigned from the user. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: UnassignRole + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Property Change policy information using a hashtable object.