Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Role parameters added #66

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cmdlets/Private/ConvertTo-TeamViewerUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 += @{
Expand Down
23 changes: 20 additions & 3 deletions Cmdlets/Public/New-TeamViewerUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand All @@ -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' `
Expand Down
20 changes: 19 additions & 1 deletion Cmdlets/Public/Set-TeamViewerUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @{}
Expand All @@ -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[$_] }
Expand Down
29 changes: 27 additions & 2 deletions Docs/Help/New-TeamViewerUser.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Create a new TeamViewer company user.
### WithPassword (Default)

```powershell
New-TeamViewerUser -ApiToken <SecureString> -Email <String> -Name <String> -Password <SecureString>
New-TeamViewerUser -ApiToken <SecureString> -Email <String> -Name <String> -Password <SecureString> [-RoleId <String>][-IgnorePredefinedRole <switch>]
[-SsoCustomerIdentifier <SecureString>] [-Culture <CultureInfo>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### WithoutPassword

```powershell
New-TeamViewerUser -ApiToken <SecureString> -Email <String> -Name <String> [-WithoutPassword]
New-TeamViewerUser -ApiToken <SecureString> -Email <String> -Name <String> [-WithoutPassword][-IgnorePredefinedRole <switch>]
[-SsoCustomerIdentifier <SecureString>] [-Culture <CultureInfo>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

Expand All @@ -50,6 +50,15 @@ PS /> New-TeamViewerUser -Email '[email protected]' -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 '[email protected]' -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
Expand Down Expand Up @@ -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.
Expand Down
43 changes: 42 additions & 1 deletion Docs/Help/Set-TeamViewerUser.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Change properties of a TeamViewer company user.
### ByParameters (Default)

```powershell
Set-TeamViewerUser -ApiToken <SecureString> -User <Object> [-Active <Boolean>] [-Email <String>]
Set-TeamViewerUser -ApiToken <SecureString> -User <Object> [-Active <Boolean>] [-Email <String>][-AssignRoleId <String[]>][-UnassignRoleId <String[]>]
[-Name <String>] [-Password <SecureString>] [-SsoCustomerIdentifier <SecureString>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down