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

Added fix to string value error #544

Merged
merged 7 commits into from
Nov 20, 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
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: 11/2/2023
# Generated on: 11/20/2023
#

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

# Version number of this module.
ModuleVersion = '2.8.2'
ModuleVersion = '2.8.3'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,21 @@ function Get-JCPolicyTemplateConfigField {
# Get Both Values:
$val1 = $field.DisplayOptions.select[$i].text
$val2 = $field.DisplayOptions.select[$i].value
# Determine which one is an int, these can sometimes be swapped
try {
[int]$val1 | Out-Null
# write-host "$($val1) is an int in first position"
$validationObject += @{$val1 = $val2 }
} catch {
[int]$val2 | Out-Null
# write-host "$($val2) is an int in second position"
$validationObject += @{$val2 = $val1 }

# Check if the val2 is a string or int
if (-not ([int]::TryParse($val2, [ref]$null))) {
$validationObject += @{$val2 = $val2 }
#Write-Error "$($val2) is a string in first position"
} else {
try {
[int]$val1 | Out-Null
# write-host "$($val1) is an int in first position"
$validationObject += @{$val1 = $val2 }
} catch {
[int]$val2 | Out-Null
# write-host "$($val2) is an int in second position"
$validationObject += @{$val2 = $val1 }
}
}
}
}
Expand Down Expand Up @@ -76,5 +82,4 @@ function Get-JCPolicyTemplateConfigField {
# Return template config field
return $templateObject
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' {
$policies | Where-Object { $_.Name -like "Pester -*" } | ForEach-Object { Remove-JcSdkPolicy -Id $_.id }
$policyTemplates = Get-JcSdkPolicyTemplate
}

Context 'Set policy with a select/multi config with string or int' {
BeforeAll {
$policyTemplate = $policyTemplates | Where-Object { $_.name -eq "system_updates_windows" }
$templateId = $policyTemplate.id
$PesterWindowsWindowsUpdateConfig = New-JCPolicy -Name "Pester - Windows - Configure Windows" -templateID $templateId -AUTO_INSTALL_SCHEDULE ScheduledInstallFirstWeek
}
It 'Sets a policy with a string multi field' {
# Update the policy with a new AUTO_INSTALL_SCHEDULE (this is a mult field)
$stringMultiValue = "ScheduledInstallSecondWeek"
$updateSchedule = Set-JCPolicy -id $PesterWindowsWindowsUpdateConfig.Id -AUTO_INSTALL_SCHEDULE $stringMultiValue

# Get the value of the Field
$fieldName = "AUTO_INSTALL_SCHEDULE"
$index = 0
for ($i = 0; $i -lt $updateSchedule.values.configFieldName.Count; $i++) {
if ($updateSchedule.values.configFieldName[$i] -eq $fieldName) {
$index = $i
break
}
}
$updateSchedule.values.value[$index] | Should -Be $stringMultiValue
}
It 'Sets a policy with a int multi field' {
# Set the policy with an int multi field
$intMultiValue = 2
{ Set-JCPolicy -id $PesterWindowsWindowsUpdateConfig.Id -AUTO_INSTALL_SCHEDULE $intMultiValue } | Should -Throw
}
}
Context 'Sets policies using the dynamic parameter set using the ByID parameter set' {
It 'Sets a policy with a string/text type dynamic parameter' {
# Define a policy with a string parameter
Expand Down
15 changes: 14 additions & 1 deletion PowerShell/ModuleChangelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
## 2.8.2
## 2.8.3

Release Date: November 20, 2023

#### RELEASE NOTES

```
Addressed the issue with Get-JCPolicyTemplateConfigField select/multi property string error
```

### BUG FIXES:

- Fixed an issue with Get-JCPolicyTemplateConfigField error when a string select/multi property is passed to an int conversion


Release Date: November 2, 2023

Expand Down