diff --git a/PowerShell/JumpCloud Module/Docs/JumpCloud.md b/PowerShell/JumpCloud Module/Docs/JumpCloud.md index ee0969774..97f468bd1 100644 --- a/PowerShell/JumpCloud Module/Docs/JumpCloud.md +++ b/PowerShell/JumpCloud Module/Docs/JumpCloud.md @@ -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.15.0 +Help Version: 2.16.0 Locale: en-Us --- diff --git a/PowerShell/JumpCloud Module/JumpCloud.psd1 b/PowerShell/JumpCloud Module/JumpCloud.psd1 index b9b1db860..b59515187 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.psd1 +++ b/PowerShell/JumpCloud Module/JumpCloud.psd1 @@ -12,7 +12,7 @@ RootModule = 'JumpCloud.psm1' # Version number of this module. - ModuleVersion = '2.15.0' + ModuleVersion = '2.16.0' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/PowerShell/JumpCloud Module/Public/Utilities/CSV_Import/Import-JCUsersFromCSV.ps1 b/PowerShell/JumpCloud Module/Public/Utilities/CSV_Import/Import-JCUsersFromCSV.ps1 index d8b0cd125..4233b9eea 100755 --- a/PowerShell/JumpCloud Module/Public/Utilities/CSV_Import/Import-JCUsersFromCSV.ps1 +++ b/PowerShell/JumpCloud Module/Public/Utilities/CSV_Import/Import-JCUsersFromCSV.ps1 @@ -369,7 +369,13 @@ Function Import-JCUsersFromCSV () { $FormatGroupOutput = $Null $CustomGroupArrayList = $Null - $CustomAttributes = $UserAdd | Get-Member | Where-Object Name -Like "*Attribute*" | Where-Object { $_.Definition -NotLike "*=" -and $_.Definition -NotLike "*null" } | Select-Object + # Get all the custom attributes that are not null + $CustomAttributes = $UserAdd | Get-Member | Where-Object Name -Like "*Attribute*" | Where-Object { $_.Definition -NotLike "*=" -and $_.Definition -NotLike "*null" } + + # Sort the attributes by number and name + $CustomAttributes = $CustomAttributes | Sort-Object { + [int]([regex]::Match($_.Name, '\d+').Value) }, + { $_.Name } Write-Verbose $CustomAttributes.name.count diff --git a/PowerShell/JumpCloud Module/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.ps1 b/PowerShell/JumpCloud Module/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.ps1 index 6898750f4..cc0261670 100755 --- a/PowerShell/JumpCloud Module/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.ps1 +++ b/PowerShell/JumpCloud Module/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.ps1 @@ -341,7 +341,13 @@ Function Update-JCUsersFromCSV () { $FormatGroupOutput = $Null $CustomGroupArrayList = $Null - $CustomAttributes = $UserUpdate | Get-Member | Where-Object Name -Like "*Attribute*" | Where-Object { $_.Definition -NotLike "*=" -and $_.Definition -NotLike "*null" } | Select-Object + # Get all the custom attributes that are not null + $CustomAttributes = $UserUpdate | Get-Member | Where-Object Name -Like "*Attribute*" | Where-Object { $_.Definition -NotLike "*=" -and $_.Definition -NotLike "*null" } + + # Sort the attributes by number and name + $CustomAttributes = $CustomAttributes | Sort-Object { + [int]([regex]::Match($_.Name, '\d+').Value) }, + { $_.Name } if ($CustomAttributes.name.count -gt 1) { try { diff --git a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCUsersFromCSV.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCUsersFromCSV.Tests.ps1 index d266199ce..459aecdf8 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCUsersFromCSV.Tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCUsersFromCSV.Tests.ps1 @@ -636,6 +636,47 @@ Describe -Tag:('JCUsersFromCSV') "Import-JCUsersFromCSV 2.14.2" { } } } +Describe -Tag:('JCUsersFromCSV') "Import-JCUsersFromCSV 2.15.1" { + Context "Import-JCUsersFromCSV with 10 or more custom attributes" { + It "When there are 10 or more custom attributes, the API should not return an error message in the status field and continue to import the user" { + $user = New-RandomUser -Domain "ImportCSVUser.$(New-RandomString -NumberOfChars 5)" + $today = Get-Date + $EnrollmentDays = 14 + $CSVDATA = @{ + Username = $user.username + LastName = $user.LastName + FirstName = $user.FirstName + Email = $user.Email + Attribute1_name = "Name" + Attribute1_value = "Value" + Attribute2_name = "Name1" + Attribute2_value = "Value1" + Attribute3_name = "Name2" + Attribute3_value = "Value2" + Attribute4_name = "Name3" + Attribute4_value = "Value3" + Attribute5_name = "Name4" + Attribute5_value = "Value4" + Attribute6_name = "Name5" + Attribute6_value = "Value5" + Attribute7_name = "Name6" + Attribute7_value = "Value6" + Attribute8_name = "Name7" + Attribute8_value = "Value7" + Attribute9_name = "Name8" + Attribute9_value = "Value8" + Attribute10_name = "Name9" + Attribute10_value = "Value9" + Attribute11_name = "Name10" + Attribute11_value = "Value10" + } + $CSVFILE = $CSVDATA | Export-Csv "$PesterParams_ImportPath/custom_attribute.csv" -Force + $importResults = Import-JCUsersFromCSV -CSVFilePath "$PesterParams_ImportPath/custom_attribute.csv" -force + # ImportResults should not be error + $importResults[0].Status | Should -Match "User Created" + } + } +} AfterAll { Get-JCUser | Where-Object Email -like *testimportcsvuser* | Remove-JCUser -force diff --git a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.Tests.ps1 index fe06f6d65..34fff4557 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.Tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.Tests.ps1 @@ -1032,6 +1032,43 @@ Describe -Tag:('JCUsersFromCSV') "Update-JCUsersFromCSV 2.14.2" { } } } + +Describe -Tag:('JCUsersFromCSV') "Update-JCUsersFromCSV 2.15.1" { + Context "User should be updated even with 10 or more custom attributes" { + It "When there are 10 or more custom attributes, the user should still be updated" { + $user = New-RandomUser -Domain "testupdatecsvuser.$(New-RandomString -NumberOfChars 5)" | New-JCUser + $CSVDATA = @{ + Username = $user.username + Attribute1_name = "Name" + Attribute1_value = "Value" + Attribute2_name = "Name1" + Attribute2_value = "Value1" + Attribute3_name = "Name2" + Attribute3_value = "Value2" + Attribute4_name = "Name3" + Attribute4_value = "Value3" + Attribute5_name = "Name4" + Attribute5_value = "Value4" + Attribute6_name = "Name5" + Attribute6_value = "Value5" + Attribute7_name = "Name6" + Attribute7_value = "Value6" + Attribute8_name = "Name7" + Attribute8_value = "Value7" + Attribute9_name = "Name8" + Attribute9_value = "Value8" + Attribute10_name = "Name9" + Attribute10_value = "Value9" + Attribute11_name = "Name10" + Attribute11_value = "Value10" + } + $CSVFILE = $CSVDATA | Export-Csv "$PesterParams_UpdatePath/custom_attribute.csv" -Force + $UpdateStatus = Update-JCUsersFromCSV -CSVFilePath "$PesterParams_UpdatePath/custom_attribute.csv" -force + # the error message should show that custom attribute names cannot contain spaces + $UpdateStatus[0].status | Should -Be "User Updated" + } + } +} AfterAll { Get-JCUser | Where-Object Email -like *testupdatecsvuser* | Remove-JCUser -force } diff --git a/PowerShell/ModuleChangelog.md b/PowerShell/ModuleChangelog.md index a5372f15b..526bd3f66 100644 --- a/PowerShell/ModuleChangelog.md +++ b/PowerShell/ModuleChangelog.md @@ -1,3 +1,17 @@ +## 2.16.0 + +Release Date: December 4, 2024 + +#### RELEASE NOTES + +``` +This release introduces a bug fix for `Import-JCUsersFromCSV` and `Update-JCUsersFromCSV` issues with importing more than 10 custom attributes +``` + +#### BUG FIXES: + +- Fixed a bug with `Import-JCUsersFromCSV` and `Update-JCUsersFromCSV` throwing error when importing 10 or more Custom Attributes due to a sorting issue + ## 2.15.0 Release Date: November 18, 2024