Skip to content

Commit

Permalink
Merge pull request #596 from TheJumpCloud/CUT-4251-RemoveAttribute-Pa…
Browse files Browse the repository at this point in the history
…rameter-Not-Working

Cut 4251 remove attribute parameter not working
  • Loading branch information
jworkmanjc authored Aug 20, 2024
2 parents a2fbae8 + fd58310 commit 939737e
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 66 deletions.
4 changes: 2 additions & 2 deletions PowerShell/JumpCloud Module/Docs/Connect-JCOnline.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The Connect-JCOnline function sets the global variable $JCAPIKEY
## SYNTAX

```
Connect-JCOnline [-force] [-JumpCloudApiKey] <String>
Connect-JCOnline [-force] [[-JumpCloudApiKey] <String>]
[[-JumpCloudOrgId] <String>] [[-JCEnvironment] <String>] [<CommonParameters>]
```

Expand Down Expand Up @@ -88,7 +88,7 @@ Type: System.String
Parameter Sets: (All)
Aliases:

Required: True
Required: False
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName)
Expand Down
2 changes: 1 addition & 1 deletion PowerShell/JumpCloud Module/Docs/JumpCloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module Name: JumpCloud
Module Guid: 31c023d1-a901-48c4-90a3-082f91b31646
Download Help Link: https://github.com/TheJumpCloud/support/wiki
Help Version: 2.13.0
Help Version: 2.13.1
Locale: en-Us
---

Expand Down
4 changes: 2 additions & 2 deletions PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Updates the JumpCloud Module Settings File
## SYNTAX

```
Set-JCSettingsFile [-moduleBannerMessageCount <PSObject>]
[-parallelOverride <PSObject>] [<CommonParameters>]
Set-JCSettingsFile [-parallelOverride <PSObject>]
[-moduleBannerMessageCount <PSObject>] [<CommonParameters>]
```

## DESCRIPTION
Expand Down
42 changes: 21 additions & 21 deletions PowerShell/JumpCloud Module/Docs/Set-JCUser.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ Set-JCUser [-Username] <String> [-email <String>] [-firstname <String>] [-lastna
-Attribute2_value <String> [<CommonParameters>]
```

### RemoveAttribute
### RemoveCustomAttribute
```
Set-JCUser [-Username] <String> [-email <String>] [-firstname <String>] [-lastname <String>]
[-password <String>] [-password_never_expires <Boolean>] [-allow_public_key <Boolean>] [-sudo <Boolean>]
[-enable_managed_uid <Boolean>] [-unix_uid <Int32>] [-unix_guid <Int32>] [-account_locked <Boolean>]
[-passwordless_sudo <Boolean>] [-externally_managed <Boolean>] [-ldap_binding_user <Boolean>]
[-enable_user_portal_multifactor <Boolean>] [-NumberOfCustomAttributes <Int32>] [-RemoveAttribute <String[]>]
[-middlename <String>] [-displayname <String>] [-jobTitle <String>] [-employeeIdentifier <String>]
[-department <String>] [-costCenter <String>] [-company <String>] [-employeeType <String>]
[-description <String>] [-location <String>] [-work_streetAddress <String>] [-work_poBox <String>]
[-work_locality <String>] [-work_region <String>] [-work_postalCode <String>] [-work_country <String>]
[-home_streetAddress <String>] [-home_poBox <String>] [-home_locality <String>] [-home_region <String>]
[-home_postalCode <String>] [-home_country <String>] [-mobile_number <String>] [-home_number <String>]
[-work_number <String>] [-work_mobile_number <String>] [-work_fax_number <String>] [-external_dn <String>]
[-external_source_type <String>] [-state <String>] [-manager <String>] [-managedAppleId <String>]
[-alternateEmail <String>] [-recoveryEmail <String>]
[-EnrollmentDays <Int32>] -Attribute1_name <String> -Attribute1_value <String> -Attribute2_name <String>
-Attribute2_value <String> [<CommonParameters>]
[-enable_user_portal_multifactor <Boolean>] [-NumberOfCustomAttributes <Int32>]
[-RemoveCustomAttribute <String[]>] [-middlename <String>] [-displayname <String>] [-jobTitle <String>]
[-employeeIdentifier <String>] [-department <String>] [-costCenter <String>] [-company <String>]
[-employeeType <String>] [-description <String>] [-location <String>] [-work_streetAddress <String>]
[-work_poBox <String>] [-work_locality <String>] [-work_region <String>] [-work_postalCode <String>]
[-work_country <String>] [-home_streetAddress <String>] [-home_poBox <String>] [-home_locality <String>]
[-home_region <String>] [-home_postalCode <String>] [-home_country <String>] [-mobile_number <String>]
[-home_number <String>] [-work_number <String>] [-work_mobile_number <String>] [-work_fax_number <String>]
[-external_dn <String>] [-external_source_type <String>] [-state <String>] [-manager <String>]
[-managedAppleId <String>] [-alternateEmail <String>] [-recoveryEmail <String>]
[-EnrollmentDays <Int32>] -Attribute1_name <String>
-Attribute1_value <String> -Attribute2_name <String> -Attribute2_value <String> [<CommonParameters>]
```

### ByID
Expand Down Expand Up @@ -107,10 +107,10 @@ This example either updates or adds the Custom Attribute 'name = Department, val

### Example 5
```powershell
PS C:\> Get-JCUserGroupMember -GroupName 'Sales' | Set-JCUser -RemoveAttribute Department
PS C:\> Get-JCUserGroupMember -GroupName 'Sales' | Set-JCUser -RemoveCustomAttribute ATTRIBUTENAME
```

This example removes the Custom Attribute with the name 'Department' from all JumpCloud Users in the JumpCloud User Group 'Sales'
This example removes the Custom Attribute with the name 'ATTRIBUTENAME' from all JumpCloud Users in the JumpCloud User Group 'Sales'

### Example 6
```powershell
Expand Down Expand Up @@ -229,7 +229,7 @@ Accept wildcard characters: False
### -ByID
Use the -ByID parameter when the UserID is being passed over the pipeline to the Set-JCUser function.
The -ByID SwitchParameter will set the ParameterSet to 'ByID' which will increase the function speed and performance.
You cannot use this with the 'RemoveAttribute' Parameter
You cannot use this with the 'RemoveCustomAttribute' Parameter
```yaml
Type: System.Management.Automation.SwitchParameter
Expand Down Expand Up @@ -792,14 +792,14 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -RemoveAttribute
### -RemoveCustomAttribute
The name of the existing Custom Attributes you wish to remove.
See an EXAMPLE for working with the -RemoveAttribute Parameter in EXAMPLE 5
See an EXAMPLE for working with the -RemoveCustomAttribute Parameter in EXAMPLE 5
```yaml
Type: System.String[]
Parameter Sets: RemoveAttribute
Aliases:
Parameter Sets: RemoveCustomAttribute
Aliases: RemoveAttribute

Required: False
Position: Named
Expand Down Expand Up @@ -901,7 +901,7 @@ The Username of the JumpCloud user you wish to modify
```yaml
Type: System.String
Parameter Sets: Username, RemoveAttribute
Parameter Sets: Username, RemoveCustomAttribute
Aliases:

Required: True
Expand Down
4 changes: 2 additions & 2 deletions PowerShell/JumpCloud Module/JumpCloud.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: JumpCloud Solutions Architect Team
#
# Generated on: 8/8/2024
# Generated on: 8/20/2024
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = 'JumpCloud.psm1'

# Version number of this module.
ModuleVersion = '2.13.0'
ModuleVersion = '2.13.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
20 changes: 9 additions & 11 deletions PowerShell/JumpCloud Module/Public/Users/Set-JCUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ Function Set-JCUser () {
[Parameter(Mandatory,
ValueFromPipelineByPropertyName = $true,
Position = 0,
ParameterSetName = 'RemoveAttribute', HelpMessage = 'The Username of the JumpCloud user you wish to modify')]

ParameterSetName = 'RemoveCustomAttribute', HelpMessage = 'The Custom Attribute of the JumpCloud user you wish to modify')]
[string]$Username,

[Parameter(Mandatory,
Expand Down Expand Up @@ -94,11 +93,12 @@ UserID has an Alias of _id. This means you can leverage the PowerShell pipeline
[int]
$NumberOfCustomAttributes,

[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'RemoveAttribute', HelpMessage = 'The name of the existing Custom Attributes you wish to remove. See an EXAMPLE for working with the -RemoveAttribute Parameter in EXAMPLE 5')]
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'RemoveCustomAttribute', HelpMessage = 'The name of the existing Custom Attributes you wish to remove. See an EXAMPLE for working with the -RemoveCustomAttribute Parameter in EXAMPLE 5')]
[string[]]
$RemoveAttribute,
[Alias('RemoveAttribute')]
$RemoveCustomAttribute,

[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'ByID', HelpMessage = 'Use the -ByID parameter when the UserID is being passed over the pipeline to the Set-JCUser function. The -ByID SwitchParameter will set the ParameterSet to ''ByID'' which will increase the function speed and performance. You cannot use this with the ''RemoveAttribute'' Parameter')]
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'ByID', HelpMessage = 'Use the -ByID parameter when the UserID is being passed over the pipeline to the Set-JCUser function. The -ByID SwitchParameter will set the ParameterSet to ''ByID'' which will increase the function speed and performance. You cannot use this with the ''RemoveCustomAttribute'' Parameter')]
[switch]
$ByID,

Expand Down Expand Up @@ -935,7 +935,7 @@ UserID has an Alias of _id. This means you can leverage the PowerShell pipeline

}

elseif ($PSCmdlet.ParameterSetName -eq 'RemoveAttribute') {
elseif ($PSCmdlet.ParameterSetName -eq 'RemoveCustomAttribute') {
if ($UserHash.Values.username -contains ($Username)) {
$URL_ID = $UserHash.GetEnumerator().Where({ $_.Value.username -contains ($Username) }).Name
Write-Debug $URL_ID
Expand All @@ -955,7 +955,7 @@ UserID has an Alias of _id. This means you can leverage the PowerShell pipeline
continue
}

if ($param.key -eq 'RemoveAttribute') {
if ($param.key -eq 'RemoveCustomAttribute') {
continue
}

Expand Down Expand Up @@ -1070,15 +1070,13 @@ UserID has an Alias of _id. This means you can leverage the PowerShell pipeline
$CurrentAttributesHash.Add($CurrentA.name, $CurrentA.value)
}

foreach ($Remove in $RemoveAttribute) {
foreach ($Remove in $RemoveCustomAttribute) {
if ($CurrentAttributesHash.ContainsKey($Remove)) {
Write-Debug "$Remove is here"
Write-Debug "$Remove is getting removed from custom attributes"
$CurrentAttributesHash.Remove($Remove)
}
}



$UpdatedAttributeArrayList = New-Object System.Collections.ArrayList


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ Describe -Tag:('ModuleValidation') 'Help File Tests' {

$ModuleRoot = (Get-Item -Path:($PSScriptRoot)).Parent.Parent
$ModuleRootFullName = $ModuleRoot.FullName
$HelpFilePopulation = Get-ChildItem -Path:($ModuleRootFullName + '/Docs/*.md') -Recurse
$excludeFunctions = @(
'Set-JCSettingsFile.md'
'Connect-JCOnline.md'
)
$HelpFilePopulation = Get-ChildItem -Path:($ModuleRootFullName + '/Docs/*.md') -Recurse -Exclude $excludeFunctions

$HelpFilePopulation | ForEach-Object {
# File should exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,20 @@ Describe -Tag:('JCUser') "Set-JCUser - CustomAttributes 1.0" {
Remove-JCUser -UserID $NewUser._id -ByID -Force
}
It "Removes a custom attribute from a User" {
$NewUser = New-RandomUserCustom -Attributes -Domain "delSetUser.$(New-RandomString -NumberOfChars 5)" | New-JCUser -NumberOfCustomAttributes 3
$UpdatedUser = Set-JCUser $NewUser.username -RemoveCustomAttribute 'Department'
[int]$NewUserAttr = $NewUser.attributes.name.count
[int]$UpdatedUserAttr = $UpdatedUser.attributes.name.count
$UpdatedUserAttr++
$match = if ($NewUserAttr -eq $UpdatedUserAttr) {
$true
} else {
$false
}
$match | Should -Be $true
Remove-JCUser -UserID $NewUser._id -ByID -Force
}
It "Removes a custom attribute from a User using the Alias 'RemoveAttribute'" {
$NewUser = New-RandomUserCustom -Attributes -Domain "delSetUser.$(New-RandomString -NumberOfChars 5)" | New-JCUser -NumberOfCustomAttributes 3
$UpdatedUser = Set-JCUser $NewUser.username -RemoveAttribute 'Department'
[int]$NewUserAttr = $NewUser.attributes.name.count
Expand Down Expand Up @@ -1235,7 +1249,7 @@ Describe -Tag:('JCUser') "Set-JCuser users phoneNumbers and attributes 1.8.0" {
$NewUser.phoneNumbers | Where-Object type -EQ work_mobile | Select-Object -ExpandProperty number | Should -Be "work_mobile_number"
$NewUser.phoneNumbers | Where-Object type -EQ work_fax | Select-Object -ExpandProperty number | Should -Be "work_fax_number"
$UpdatedUser = Set-JCUser -Username $NewUser.username -NumberOfCustomAttributes 1 -Attribute1_name 'attr1' -Attribute1_value 'one'
$UpdatedUser = Set-JCUser -Username $NewUser.username -RemoveAttribute 'attr1' -work_fax_number "new_work_fax_number"
$UpdatedUser = Set-JCUser -Username $NewUser.username -RemoveCustomAttribute 'attr1' -work_fax_number "new_work_fax_number"
$UpdatedUser.phoneNumbers | Where-Object type -EQ mobile | Select-Object -ExpandProperty number | Should -Be "mobile_number"
$UpdatedUser.phoneNumbers | Where-Object type -EQ home | Select-Object -ExpandProperty number | Should -Be "home_number"
$UpdatedUser.phoneNumbers | Where-Object type -EQ work | Select-Object -ExpandProperty number | Should -Be "work_number"
Expand Down Expand Up @@ -1301,13 +1315,13 @@ Describe -Tag:('JCUser') "Set-JCUser MFA Enrollment periods 1.10" {
$Newuser.mfa.exclusion | Should -Be $true
$Newuser | Remove-JCUser -ByID -force
}
It "Updates an existing user with enable_user_portal_multifactor -eq True with removeAttributes" {
It "Updates an existing user with enable_user_portal_multifactor -eq True with RemoveCustomAttributes" {
$CreateUser = New-RandomUser -Domain "delSetUser.$(New-RandomString -NumberOfChars 5)" -Attributes | New-JCUser -NumberOfCustomAttributes 2
$NewUser = $CreateUser | Set-JCUser -enable_user_portal_multifactor $true -RemoveAttribute 'Department', 'Lang'
$NewUser = $CreateUser | Set-JCUser -enable_user_portal_multifactor $true -RemoveCustomAttribute 'Department', 'Lang'
$Newuser.mfa.exclusion | Should -Be $true
$Newuser | Remove-JCUser -ByID -force
}
It "Updates an existing user with enable_user_portal_multifactor -eq True and a 7 days specified for EnrollmentDays with removeAttributes" {
It "Updates an existing user with enable_user_portal_multifactor -eq True and a 7 days specified for EnrollmentDays with RemoveCustomAttributes" {
$CreateUser = New-RandomUser -Domain "delSetUser.$(New-RandomString -NumberOfChars 5)" | New-JCUser -enable_user_portal_multifactor $true
$EnrollmentDays = 7
$NewUser = $CreateUser | Set-JCUser -enable_user_portal_multifactor $true -EnrollmentDays $EnrollmentDays
Expand Down
Loading

0 comments on commit 939737e

Please sign in to comment.