diff --git a/.circleci/workflows.yml b/.circleci/workflows.yml index 8d8b54ad7..03f2ed3d6 100755 --- a/.circleci/workflows.yml +++ b/.circleci/workflows.yml @@ -32,7 +32,7 @@ parameters: description: "Release Type. Accepted values [ Major, Minor, Patch ]" type: enum enum: ["Major", "Minor", "Patch"] - default: "Patch" + default: "Minor" RequiredModulesRepo: description: "PowerShell Repository for JumpCloud SDKs" type: enum @@ -49,7 +49,7 @@ parameters: PublishToPSGallery: description: "When `true` and when run against Master branch, this workflow will publish the latest code to PSGallery" type: boolean - default: false + default: true ManualModuleVersion: description: "When `true` the pipeline will use the Module Version specified in JumpCloud Module JumpCloud.psd1 file" type: boolean diff --git a/PowerShell/JumpCloud Module/Docs/JumpCloud.md b/PowerShell/JumpCloud Module/Docs/JumpCloud.md index 0da8bc301..d1e0ec3e1 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.6.0 +Help Version: 2.7.0 Locale: en-US --- diff --git a/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md b/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md index 0c5eb8b6f..2567c1d72 100644 --- a/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md +++ b/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md @@ -72,6 +72,14 @@ PS C:\> New-JCPolicy -TemplateName darwin_Login_Window_Text -Values $policyValu This would create a new macOS Login Window Text policy with the login window text set to `Welcome to JumpCloud` with the `macOS - Login Window Policy` name. The policy values are set using the `values` parameter. Objects passed into the `values` parameter set must contain the `value` for the policy config field and a `configFieldID`. To get a policy value object, search for any existing policy using `Get-JCPolicy` the `values` object returned from that cmdlet will contain the config fields required to build new policies or edit existing ones. +### Example 5 + +```PowerShell +PS C:\> New-JCPolicy -TemplateName windows_Advanced:_Custom_Registry_Keys -Name "Windows - Imported Custom Registry Settings" -RegistryFile "/path/to/registryFile.reg" +``` + +This command would create a new Windows Custom Registry Policy named "Windows - Imported Custom Registry Settings" and populate the values from a registry file. .Reg registry files can be passed into New-JCPolicy as long as the TemplateName is specified with the corresponding "windows_Advanced:\_Custom_Registry_Keys" template. .Reg files will be converted and uploaded to the JumpCloud policy as long as they contain "DWORD", "EXPAND_SZ", "MULTI_SZ", "SZ" or "QWORD" type data. + ## PARAMETERS ### -Name diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md b/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md index 5e2ff89fa..c307cd146 100644 --- a/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md +++ b/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md @@ -72,6 +72,22 @@ PS C:\> Set-JCPolicy -PolicyName "macOS - Login Window Policy" -Values $policyV This would update the policy named `macOS - Login Window Policy` with the login window text set to `Welcome to JumpCloud`. The policy values are set using the `values` parameter. Objects passed into the `values` parameter set must contain the `value` for the policy config field and a `configFieldID`. To get a policy value object, search for any existing policy using `Get-JCPolicy` the `values` object returned from that cmdlet will contain the config fields required to build new policies or edit existing ones. +### Example 5 + +```powershell +PS C:\> Set-JCPolicy -PolicyName "Windows - Imported Custom Registry Settings" -RegistryFile "/path/to/registryFile.reg" +``` + +This command would append the registry policy's existing values with the imported set of .Reg keys specified by the "RegistryFile" parameter. .Reg files will be converted and uploaded to the JumpCloud policy as long as they contain "DWORD", "EXPAND_SZ", "MULTI_SZ", "SZ" or "QWORD" type data. + +### Example 6 + +```powershell +PS C:\> Set-JCPolicy -PolicyName "Windows - Imported Custom Registry Settings" -RegistryFile "/path/to/registryFile.reg" -RegistryOverwrite +``` + +This command would overwrite the registry policy's existing values with the imported set of .Reg keys specified by the "RegistryFile" parameter. .Reg files will be converted and uploaded to the JumpCloud policy as long as they contain "DWORD", "EXPAND_SZ", "MULTI_SZ", "SZ" or "QWORD" type data. + ## PARAMETERS ### -NewName diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md b/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md index f8bf10130..ba6b37a0c 100644 --- a/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md +++ b/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md @@ -14,7 +14,7 @@ Updates the JumpCloud Module Settings File ## SYNTAX ``` -Set-JCSettingsFile [-parallelOverride ] [-moduleBannerMessageCount ] [] +Set-JCSettingsFile [-moduleBannerMessageCount ] [-parallelOverride ] [] ``` ## DESCRIPTION diff --git a/PowerShell/JumpCloud Module/JumpCloud.nuspec b/PowerShell/JumpCloud Module/JumpCloud.nuspec index 9360b23a2..83520d9ef 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.6.0 + 2.7.0.9326-202308011615 PowerShell functions to manage a JumpCloud Directory-as-a-Service JumpCloud Solutions Architect Team JumpCloud diff --git a/PowerShell/JumpCloud Module/JumpCloud.psd1 b/PowerShell/JumpCloud Module/JumpCloud.psd1 index c7f318b8d..583f456d2 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.psd1 +++ b/PowerShell/JumpCloud Module/JumpCloud.psd1 @@ -3,7 +3,7 @@ # # Generated by: JumpCloud Solutions Architect Team # -# Generated on: 6/21/2023 +# Generated on: 8/1/2023 # @{ @@ -12,7 +12,7 @@ RootModule = 'JumpCloud.psm1' # Version number of this module. -ModuleVersion = '2.6.0' +ModuleVersion = '2.7.0' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 index 0a20f1c58..ee052bb3b 100644 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 @@ -22,7 +22,7 @@ Function Get-JCResults { $errorResults = [System.Collections.Concurrent.ConcurrentQueue[Exception]]::new() } else { Write-Debug "Running in Sequential" - $resultsArray = [System.Collections.Generic.List[object]]::new() + $resultsArray = [System.Collections.ArrayList]::new() } $totalCount = 1 $limit = [int]$limit @@ -170,15 +170,24 @@ Function Get-JCResults { else { if ($totalCountHeader) { # Add results to results list - $content = $response.Content - [void]$resultsArray.Add($content) + $content = $response.Content | ConvertFrom-Json + # Check to see size of content + if ($content.Count -le 1) { + [void]$resultsArray.Add($content) + } else { + [void]$resultsArray.AddRange($content) + } } else { # Add results to results list $content = $response.Content | ConvertFrom-Json if ($null -eq $content.results) { [void]$resultsArray.Add($content) } else { - [void]$resultsArray.AddRange($content.results) + if ($($content.results).Count -le 1) { + [void]$resultsArray.Add($content.results) + } else { + [void]$resultsArray.AddRange($content.results) + } } } @@ -220,25 +229,30 @@ Function Get-JCResults { # Add results to results list if ($totalCountHeader) { # Add results to results list - $content = $response.Content - [void]$resultsArray.Add($content) - Write-Debug ("Page: $($i+1) Amount: " + ($content | ConvertFrom-Json).Count) + $content = $response.Content | ConvertFrom-Json + if ($content.Count -le 1) { + [void]$resultsArray.Add($content) + } else { + [void]$resultsArray.AddRange($content) + } } else { # Add results to results list $content = $response.Content | ConvertFrom-Json if ($null -eq $content.results) { [void]$resultsArray.Add($content) - Write-Debug ("Page: $($i+1) Amount: " + ($content | ConvertFrom-Json).Count) } else { - [void]$resultsArray.AddRange($content.results) - Write-Debug ("Page: $($i+1) Amount: " + ($content.results).Count) + if ($($content.results).Count -le 1) { + [void]$resultsArray.Add($content.results) + } else { + [void]$resultsArray.AddRange($content.results) + } } } } } } end { - if ($totalCountHeader) { + if ($parallel -and $totalCountHeader) { $resultsArray = $resultsArray | ConvertFrom-Json } # Return complete results diff --git a/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 b/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 new file mode 100644 index 000000000..88ccf81cc --- /dev/null +++ b/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 @@ -0,0 +1,107 @@ +function Convert-RegToPSObject { + param( + [Parameter(Mandatory = $true)] + [ValidateScript({ + if (-Not ($_ | Test-Path) ) { + throw "File or folder does not exist" + } + if (-Not ($_ | Test-Path -PathType Leaf) ) { + throw "The Path argument must be a file. Folder paths are not allowed." + } + if ($_ -notmatch "(\.reg)") { + throw "The file specified in the path argument must be of type reg" + } + return $true + })] + [System.IO.FileInfo]$regFilePath + ) + begin { + $regKeys = [System.Collections.ArrayList]@() + [string]$text = $null + $regContent = Get-Content $RegFilePath | Where-Object { ![string]::IsNullOrWhiteSpace($_) } | ForEach-Object { $_.Trim() } + $joinedlines = @() + for ($i = 0; $i -lt $regContent.count; $i++) { + if ($regContent[$i].EndsWith("\")) { + $text = $text + ($regContent[$i] -replace "\\").trim() + } else { + $joinedlines += $text + $regContent[$i] + [string]$text = $null + } + } + } + process { + foreach ($line in $joinedlines) { + # Extract the registry path + if ($line.StartsWith("[")) { + # Throw error if registry is no HKEY_LOCAL_MACHINE + if ($line -notmatch "HKEY_LOCAL_MACHINE") { + throw "JumpCloud Policies only support HKEY_LOCAL_MACHINE/HKLM registry keys" + } else { + $path = $line.TrimStart("[").TrimEnd("]").Replace("HKEY_LOCAL_MACHINE", "").Replace("\\\\", "\\").TrimStart('\') + } + } else { + # Extract Values + if ($line.Contains("=")) { + $valueObject = $($line.Split("=")).Trim("`"") + $valueName = $($valueObject[0]).Trim() + if ($valueObject[1].StartsWith("dword:")) { + #DWORD + $customRegType = "DWORD" + $customData = [int]"0x$(($valueObject[1]).Substring(6))" + } elseif ($valueObject[1].StartsWith("hex(b):")) { + #QWORD + $customRegType = "QWORD" + $value = ($valueObject[1]).Substring(7).split(",") + # Convert to value + $value = for ($i = $value.count - 1; $i -ge 0; $i--) { + $value[$i] + } + $hexValue = '0x' + ($value -join "").trimstart('0') + $customData = [int]$hexValue + } elseif ($valueObject[1].StartsWith("hex(7):")) { + #MULTI_SZ + $customRegType = "multiString" + $value = ($valueObject[1]).Replace("hex(7):", "").split(",") + $value = for ($i = 0; $i -lt $value.count; $i += 2) { + if ($value[$i] -ne '00') { + [string][char][int]('0x' + $value[$i]) + } else { + "\0" + } + } + $customData = $value -join "" + } elseif ($valueObject[1].StartsWith("hex(2):")) { + #EXPAND_SZ + $customRegType = "expandString" + $value = ($valueObject[1]).Substring(7).split(",") + $value = for ($i = 0; $i -lt $value.count; $i += 2) { + if ($value[$i] -ne '00') { + [string][char][int]('0x' + $value[$i]) + } + } + $customData = $value -join "" + } else { + #STRING + $customRegType = "String" + $customData = $($valueObject[1]).Trim("`"") + } + + # Create PSCustomObject for endpoint + $regKey = [PSCustomObject]@{ + 'customLocation' = $path + 'customValueName' = $valueName + 'customRegType' = $customRegType + 'customData' = $customData + } + + # Add object to ArrayList + $regKeys.Add($regKey) | Out-Null + } + } + } + } + end { + # Return objectarray containing keys + return , $regKeys + } +} \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 b/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 index 7eb1df5e9..0611c7751 100644 --- a/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 +++ b/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 @@ -97,6 +97,16 @@ function New-JCPolicy { # Add the param $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParamName_Filter, $paramType, $AttributeCollection) $RuntimeParameterDictionary.Add($ParamName_Filter, $RuntimeParameter) + if ($ParamName_Filter -eq "customRegTable") { + $RegImport_RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary + $RegImport_AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] + $RegImport_ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute + $RegImport_paramType = [System.IO.FileInfo] + $RegImport_ParameterAttribute.HelpMessage = 'A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template.' + $RegImport_AttributeCollection.Add($RegImport_ParameterAttribute) + $RegImport_RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter('RegistryFile', $RegImport_paramType, $RegImport_AttributeCollection) + $RuntimeParameterDictionary.Add('RegistryFile', $RegImport_RuntimeParameter) + } } # Returns the dictionary return $RuntimeParameterDictionary @@ -204,6 +214,15 @@ function New-JCPolicy { } } $newObject.Add($templateObject.objectMap[$i]) | Out-Null + } elseif ('RegistryFile' -in $params.Keys) { + try { + $regKeys = Convert-RegToPSObject -regFilePath $($params.'RegistryFile') + } catch { + throw $_ + } + # Set the registryFile as the customRegTable + $templateObject.objectMap[0].value = $regKeys + $newObject.Add($templateObject.objectMap[0]) | Out-Null } else { # Else if the dynamicParam for a config field is not specified, set the value from the defaultValue $templateObject.objectMap[$i].value = $templateObject.objectMap[$i].defaultValue @@ -258,6 +277,7 @@ function New-JCPolicy { } | ConvertTo-Json -Depth 99 } + $headers = @{ 'x-api-key' = $env:JCApiKey 'x-org-id' = $env:JCOrgId diff --git a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 index f45d0b239..f517e7f2f 100644 --- a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 +++ b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 @@ -35,6 +35,9 @@ function Set-JCPolicy { if ([string]::IsNullOrEmpty($foundPolicy.ID)) { throw "Could not find policy by ID" } + if (($foundPolicy.ID).count -gt 1) { + throw "multiple policies with the same name were found, please specify a policy by ID" + } } elseif ($PSBoundParameters["PolicyName"]) { $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute @@ -45,6 +48,9 @@ function Set-JCPolicy { if ([string]::IsNullOrEmpty($foundPolicy.ID)) { throw "Could not find policy by specified Name" } + if (($foundPolicy.ID).count -gt 1) { + throw "multiple policies with the same name were found, please specify a policy by ID" + } } # If policy is identified, get the dynamic policy set if ($foundPolicy.id -And ($PSBoundParameters["PolicyName"] -OR $PSBoundParameters["PolicyID"])) { @@ -99,6 +105,26 @@ function Set-JCPolicy { # Add the param $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParamName_Filter, $paramType, $AttributeCollection) $RuntimeParameterDictionary.Add($ParamName_Filter, $RuntimeParameter) + if ($ParamName_Filter -eq "customRegTable") { + $RegImport_RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary + $RegImport_AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] + $RegImport_ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute + $RegImport_paramType = [System.IO.FileInfo] + $RegImport_ParameterAttribute.HelpMessage = 'A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template.' + $RegImport_AttributeCollection.Add($RegImport_ParameterAttribute) + $RegImport_RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter('RegistryFile', $RegImport_paramType, $RegImport_AttributeCollection) + $RuntimeParameterDictionary.Add('RegistryFile', $RegImport_RuntimeParameter) + } + if ($ParamName_Filter -eq "customRegTable") { + $RegImport_RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary + $RegImport_AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] + $RegImport_ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute + $RegImport_paramType = [Switch] + $RegImport_ParameterAttribute.HelpMessage = 'When specified along with the RegistryFile parameter, existing registry values will be overwritten' + $RegImport_AttributeCollection.Add($RegImport_ParameterAttribute) + $RegImport_RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter('RegistryOverwrite', $RegImport_paramType, $RegImport_AttributeCollection) + $RuntimeParameterDictionary.Add('RegistryOverwrite', $RegImport_RuntimeParameter) + } } # Returns the dictionary return $RuntimeParameterDictionary @@ -118,6 +144,9 @@ function Set-JCPolicy { if ([string]::IsNullOrEmpty($foundPolicy.ID)) { throw "Could not find policy by ID" } + if (($foundPolicy.ID).count -gt 1) { + throw "multiple policies with the same name were found, please specify a policy by ID" + } } $templateObject = Get-JCPolicyTemplateConfigField -templateID $foundPolicy.Template.Id # First set the name from PSParamSet if set; else set from policy @@ -208,6 +237,23 @@ function Set-JCPolicy { } } $newObject.Add($templateObject.objectMap[$i]) | Out-Null + } elseif ('RegistryFile' -in $params.Keys) { + try { + $regKeys = Convert-RegToPSObject -regFilePath $($params.'RegistryFile') + } catch { + throw $_ + } + # Set the registryFile as the customRegTable + if ('RegistryOverwrite' -in $params.Keys) { + $templateObject.objectMap[0].value = $regKeys + $newObject.Add($templateObject.objectMap[0]) | Out-Null + } else { + $registryList = New-Object System.Collections.ArrayList + $registryList += $foundPolicy.values.value + $registryList += $regKeys + $templateObject.objectMap[0].value += $registryList + $newObject.Add($templateObject.objectMap[0]) | Out-Null + } } else { # Else if the dynamicParam for a config field is not specified, set the value from the defaultValue $templateObject.objectMap[$i].value = ($foundPolicy.values | Where-Object { $_.configFieldID -eq $templateObject.objectMap[$i].configFieldID }).value @@ -215,6 +261,15 @@ function Set-JCPolicy { } } $updatedPolicyObject = $newObject | Select-Object configFieldID, configFieldName, value + if ($registryFile) { + try { + $regKeys = Convert-RegToPSObject -regFilePath $registryFile + } catch { + throw $_ + } + $updatedPolicyObject.value += $regKeys + Write-Debug $updatedPolicyObject + } } elseif ($values) { # begin value param set $updatedPolicyObject = New-Object System.Collections.ArrayList @@ -283,4 +338,4 @@ function Set-JCPolicy { end { return $response | Select-Object -Property "name", "id", "templateID", "values", "template" } -} \ No newline at end of file +} diff --git a/PowerShell/JumpCloud Module/Tests/DefineEnvironment.ps1 b/PowerShell/JumpCloud Module/Tests/DefineEnvironment.ps1 index 8b35e4445..dabe3fae5 100644 --- a/PowerShell/JumpCloud Module/Tests/DefineEnvironment.ps1 +++ b/PowerShell/JumpCloud Module/Tests/DefineEnvironment.ps1 @@ -79,6 +79,8 @@ $PesterParamsHash_Common = @{ JCDeployment_10_CSV = "$PSScriptRoot/Csv_Files/commandDeployment/JCDeployment_10.csv" ImportPath = "$PSScriptRoot/Csv_Files/import" UpdatePath = "$PSScriptRoot/Csv_Files/update" + # Registry Files + RegistryFilePath = "$PSScriptRoot/Reg_File/PesterRegFile.reg" # Policy Info MultiplePolicyList = @('1 Linux', 'Disable USB Storage - Linux') SinglePolicyList = @('Disable USB Storage - Linux') diff --git a/PowerShell/JumpCloud Module/Tests/Private/Policies/Convert-RegToPSObject.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/Policies/Convert-RegToPSObject.Tests.ps1 new file mode 100644 index 000000000..ef1a715df --- /dev/null +++ b/PowerShell/JumpCloud Module/Tests/Private/Policies/Convert-RegToPSObject.Tests.ps1 @@ -0,0 +1,40 @@ +Describe -Tag:('JCPolicy') 'Registry File Tests' { + Context 'Test Reg File Conversion' { + $regFile = Convert-RegToPSObject -regFilePath $PesterParams_RegistryFilePath + It 'Convert-RegToPSObject should return object with values' { + foreach ($regKey in $regFile) { + $regKey.customLocation | Should -Not -BeNullOrEmpty + $regKey.customValueName | Should -Not -BeNullOrEmpty + $regKey.customRegType | Should -Not -BeNullOrEmpty + $regKey.customData | Should -Not -BeNullOrEmpty + } + } + It 'Convert-RegToPSObject validate correct values' { + foreach ($regKey in $regFile) { + $regKey.customLocation | Should -Be "SOFTWARE\Policies\Microsoft\Power\PowerSettings" + switch ($regKey.customRegType) { + DWORD { + $regKey.customValueName | Should -Be "DWORDValue" + $regKey.customData | Should -Be 0 + } + QWORD { + $regKey.customValueName | Should -Be "QWORDValue" + $regKey.customData | Should -Be 16 + } + multiString { + $regKey.customValueName | Should -Be "MULTISZValue" + $regKey.customData | Should -Be "Test1\0Test2\0\0" + } + expandString { + $regKey.customValueName | Should -Be "EXPANDSZValue" + $regKey.customData | Should -Be "Test1" + } + String { + $regKey.customValueName | Should -Be "ActivePowerScheme" + $regKey.customData | Should -Be "8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c" + } + } + } + } + } +} \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Tests/Public/Policies/New-JCPolicy.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Policies/New-JCPolicy.tests.ps1 index 27f668e0f..7686cf65f 100644 --- a/PowerShell/JumpCloud Module/Tests/Public/Policies/New-JCPolicy.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Policies/New-JCPolicy.tests.ps1 @@ -3,7 +3,7 @@ Describe -Tag:('JCPolicy') 'New-JCPolicy' { Connect-JCOnline -JumpCloudApiKey:($PesterParams_ApiKey) -force | Out-Null $policies = Get-JCPolicy - $policies | Where-Object { $_.Name -like "Pester -*" } | % { Remove-JcSdkPolicy -id $_.id } + $policies | Where-Object { $_.Name -like "Pester -*" } | ForEach-Object { Remove-JcSdkPolicy -Id $_.id } $policyTemplates = Get-JcSdkPolicyTemplate } @@ -11,7 +11,7 @@ Describe -Tag:('JCPolicy') 'New-JCPolicy' { It 'Creates a new policy that tests textbox string' { $policyTemplate = $policyTemplates | Where-Object { $_.name -eq "rename_local_administrator_account_windows" } $templateId = $policyTemplate.id - $stringPolicy = New-JCPolicy -name "Pester - Textbox String" -templateID $templateId -ADMINISTRATORSTRING "Test String" + $stringPolicy = New-JCPolicy -Name "Pester - Textbox String" -templateID $templateId -ADMINISTRATORSTRING "Test String" # Should not be null $stringPolicy.values.value | Should -Be "Test String" } @@ -19,16 +19,16 @@ Describe -Tag:('JCPolicy') 'New-JCPolicy' { $policyTemplate = $policyTemplates | Where-Object { $_.name -eq "lock_screen_darwin" } $templateId = $policyTemplate.id $intValue = 45 - $intPolicy = New-JCPolicy -name "Pester - Integer Dynamic" -templateID $templateId -timeout $intValue + $intPolicy = New-JCPolicy -Name "Pester - Integer Dynamic" -templateID $templateId -timeout $intValue $intPolicy.values.value | Should -Be $intValue } It 'Creates a new policy that tests boolean' { $policyTemplate = $policyTemplates | Where-Object { $_.name -eq "allow_the_use_of_biometrics_windows" } $templateId = $policyTemplate.id - $booleanPolicy = New-JCPolicy -name "Pester - Boolean" -templateID $templateId -ALLOWUSEOFBIOMETRICS $true + $booleanPolicy = New-JCPolicy -Name "Pester - Boolean" -templateID $templateId -ALLOWUSEOFBIOMETRICS $true # Should not be null??? - $booleanPolicy.values.value | Should -be $true + $booleanPolicy.values.value | Should -Be $true } It 'Creates a new policy that tests registry' { $policyTemplate = $policyTemplates | Where-Object { $_.name -eq "custom_registry_keys_policy_windows" } @@ -51,33 +51,33 @@ Describe -Tag:('JCPolicy') 'New-JCPolicy' { $templateId = $policyTemplate.id $listboxPolicy = New-JCPolicy -Name "Pester - Mac - Encrypted DNS Policy New" -templateID $templateId -ServerAddresses "Test Pester Address" -ServerURL "Test URL" -SupplementalMatchDomains "Test Domain" # set should set the policies to the correct type - ($listboxPolicy.values | Where-object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.getType() | Should -BeOfType object - ($listboxPolicy.values | Where-object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.getType() | Should -BeOfType object - ($listboxPolicy.values | Where-object { $_.ConfigFieldName -eq 'ServerURL' }).value.getType().Name | Should -BeOfType string + ($listboxPolicy.values | Where-Object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.getType() | Should -BeOfType object + ($listboxPolicy.values | Where-Object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.getType() | Should -BeOfType object + ($listboxPolicy.values | Where-Object { $_.ConfigFieldName -eq 'ServerURL' }).value.getType().Name | Should -BeOfType string # since we set only one value the count for each of these objects should be 1 - ($listboxPolicy.values | Where-object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.count | Should -Be 1 - ($listboxPolicy.values | Where-object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.count | Should -Be 1 + ($listboxPolicy.values | Where-Object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.count | Should -Be 1 + ($listboxPolicy.values | Where-Object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.count | Should -Be 1 # Create another policy w/ multiple values here and test $multipleServerAddresses = @("Test Pester Address1", "Test Pester Address2") $multipleSupplementalMatchDomains = @("Test Domain3", "Test Domain4") $listboxPolicyMultiple = New-JCPolicy -Name "Pester - Mac - Encrypted DNS Policy New Multiple" -templateID $templateId -ServerAddresses $multipleServerAddresses -ServerURL "Test URL" -SupplementalMatchDomains $multipleSupplementalMatchDomains # set should set the policies to the correct type - ($listboxPolicyMultiple.values | Where-object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.getType() | Should -BeOfType object - ($listboxPolicyMultiple.values | Where-object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.getType() | Should -BeOfType object - ($listboxPolicyMultiple.values | Where-object { $_.ConfigFieldName -eq 'ServerURL' }).value.getType().Name | Should -BeOfType string + ($listboxPolicyMultiple.values | Where-Object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.getType() | Should -BeOfType object + ($listboxPolicyMultiple.values | Where-Object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.getType() | Should -BeOfType object + ($listboxPolicyMultiple.values | Where-Object { $_.ConfigFieldName -eq 'ServerURL' }).value.getType().Name | Should -BeOfType string # Count for listbox policy should be 2 - ($listboxPolicyMultiple.values | Where-object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.count | Should -Be 2 - ($listboxPolicyMultiple.values | Where-object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.count | Should -Be 2 + ($listboxPolicyMultiple.values | Where-Object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.count | Should -Be 2 + ($listboxPolicyMultiple.values | Where-Object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.count | Should -Be 2 # validate that the items are correct: - ($listboxPolicyMultiple.values | Where-object { $_.ConfigFieldName -eq 'ServerAddresses' }).value | Should -Be $multipleServerAddresses - ($listboxPolicyMultiple.values | Where-object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value | Should -Be $multipleSupplementalMatchDomains + ($listboxPolicyMultiple.values | Where-Object { $_.ConfigFieldName -eq 'ServerAddresses' }).value | Should -Be $multipleServerAddresses + ($listboxPolicyMultiple.values | Where-Object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value | Should -Be $multipleSupplementalMatchDomains } It 'Creates a new policy that tests upload file' { $policyTemplate = $policyTemplates | Where-Object { $_.name -eq "custom_font_policy_darwin" } $templateId = $policyTemplate.id # Upload ps1 files for this test - $firstFile = Get-ChildItem $($PSScriptRoot) -Filter *.ps1 | Select -First 1 + $firstFile = Get-ChildItem $($PSScriptRoot) -Filter *.ps1 | Select-Object -First 1 $fileBase64 = [convert]::ToBase64String((Get-Content -Path $firstFile.FullName -AsByteStream)) # Add a new policy with file type: @@ -87,7 +87,7 @@ Describe -Tag:('JCPolicy') 'New-JCPolicy' { It 'Creates a new policy that select, string, boolean' { $policyTemplate = $policyTemplates | Where-Object { $_.name -eq "app_notifications_darwin" } $templateId = $policyTemplate.id - $multipleValPolicy = New-JCPolicy -name "Pester - Test multiple" -templateID $templateId -AlertType "Temporary Banner" -BundleIdentifier "Test" -PreviewType "Always" -BadgesEnabled $true + $multipleValPolicy = New-JCPolicy -Name "Pester - Test multiple" -templateID $templateId -AlertType "Temporary Banner" -BundleIdentifier "Test" -PreviewType "Always" -BadgesEnabled $true #Test each param ($multipleValPolicy.values | Where-Object { $_.configFieldName -eq "AlertType" }).value | Should -Be 1 # 1 is the value for Temporary Banner on the dropdown ($multipleValPolicy.values | Where-Object { $_.configFieldName -eq "BundleIdentifier" }).value | Should -Be "Test" @@ -100,16 +100,16 @@ Describe -Tag:('JCPolicy') 'New-JCPolicy' { It 'Creates a policy using the pipeline parameters boolean' { $policyTemplate = $policyTemplates | Where-Object { $_.name -eq "allow_the_use_of_biometrics_windows" } $templateId = $policyTemplate.id - $firstPolicy = New-JCPolicy -name "Pester - value boolean" -templateID $templateId -ALLOWUSEOFBIOMETRICS $false - $valuePolicy = New-JCPolicy -name "Pester - New Policy Value Boolean Test" -values $firstPolicy.values -templateID $templateId + $firstPolicy = New-JCPolicy -Name "Pester - value boolean" -templateID $templateId -ALLOWUSEOFBIOMETRICS $false + $valuePolicy = New-JCPolicy -Name "Pester - New Policy Value Boolean Test" -values $firstPolicy.values -templateID $templateId $valuePolicy.value.values | Should -Be $firstPolicy.value.values } It 'Creates a new policy that tests integer' { $policyTemplate = $policyTemplates | Where-Object { $_.name -eq "lock_screen_darwin" } $templateId = $policyTemplate.id $intValue = 45 - $firstIntPolicy = New-JCPolicy -name "Pester - Integer Values" -templateID $templateId -timeout $intValue - $valueIntPolicy = New-JCPolicy -name "Pester - Value Integer" -templateID $templateId -Values $firstIntPolicy.values + $firstIntPolicy = New-JCPolicy -Name "Pester - Integer Values" -templateID $templateId -timeout $intValue + $valueIntPolicy = New-JCPolicy -Name "Pester - Value Integer" -templateID $templateId -Values $firstIntPolicy.values $valueIntPolicy.values.value | Should -Be $firstIntPolicy.values.value } It 'Creates a new policy that tests values registry' { @@ -126,7 +126,7 @@ Describe -Tag:('JCPolicy') 'New-JCPolicy' { # add values to list $policyValueList.add($policyValue) $tablePolicy = New-JCPolicy -Name "Pester - Registry value test" -templateID $templateId -customRegTable $policyValueList - $valuePolicy = New-JCPolicy -name "Pester - new value registry test" -templateID $templateId -values $tablePolicy.values + $valuePolicy = New-JCPolicy -Name "Pester - new value registry test" -templateID $templateId -values $tablePolicy.values $valuePolicy.value.values | Should -Be $tablePolicy.value.values } It 'Creates a new policy that tests values upload file' { @@ -134,19 +134,19 @@ Describe -Tag:('JCPolicy') 'New-JCPolicy' { $templateId = $policyTemplate.id # Upload ps1 files for this test - $firstFile = Get-ChildItem $($PSScriptRoot) -Filter *.ps1 | Select -First 1 + $firstFile = Get-ChildItem $($PSScriptRoot) -Filter *.ps1 | Select-Object -First 1 # Add a new policy with file type: - $newFilePolicy = New-JCPolicy -name "Pester - Values File" -templateID $templateId -setFont $firstFile.FullName -setName "Roboto Light" - $valuePolicy = New-JCPolicy -name "Pester - Values Second Policy File" -templateID $templateId -values $newFilePolicy.values + $newFilePolicy = New-JCPolicy -Name "Pester - Values File" -templateID $templateId -setFont $firstFile.FullName -setName "Roboto Light" + $valuePolicy = New-JCPolicy -Name "Pester - Values Second Policy File" -templateID $templateId -values $newFilePolicy.values $valuePolicy.values.value | Should -Be $newFilePolicy.values.value } It 'Creates a new policy that tests values parameters string' { $policyTemplate = $policyTemplates | Where-Object { $_.name -eq "rename_local_administrator_account_windows" } $templateId = $policyTemplate.id - $newPolicy = New-JCPolicy -name "Pester - Test textbox" -templateID $templateId -ADMINISTRATORSTRING "Test String" + $newPolicy = New-JCPolicy -Name "Pester - Test textbox" -templateID $templateId -ADMINISTRATORSTRING "Test String" # Should not be null - $valuePolicy = New-JCPolicy -name "Pester - Values New Policy String Test" -templateID $templateId -values $newPolicy.values + $valuePolicy = New-JCPolicy -Name "Pester - Values New Policy String Test" -templateID $templateId -values $newPolicy.values $valuePolicy.value.values | Should -Be $newPolicy.value.values } } @@ -160,7 +160,7 @@ Describe -Tag:('JCPolicy') 'New-JCPolicy' { It 'When a user specifies a non-valid dynamicParameter' { $policyTemplate = $policyTemplates | Where-Object { $_.name -eq "rename_local_administrator_account_windows" } $templateId = $policyTemplate.id - { New-JCPolicy -name "Pester - Test textbox $(new-randomString -NumberOfChars 8)" -templateID $templateId -fakeParam "Test String" } | Should -Throw + { New-JCPolicy -Name "Pester - Test textbox $(new-randomString -NumberOfChars 8)" -templateID $templateId -fakeParam "Test String" } | Should -Throw } } @@ -246,15 +246,15 @@ Describe -Tag:('JCPolicy') 'New-JCPolicy' { It 'customRegTable param should not throw if an invalid customRegType is passed in' { $registryTemplate = $policyTemplates | Where-Object { $_.name -eq "custom_registry_keys_policy_windows" } $data = @{customData = 'someString'; customLocation = 'location'; customRegType = 'DWORD'; customValueName = 'registryKeyValue' } - { New-JCPolicy -templateID $registryTemplate.id -customRegTable $data -Name "Pester - Registry Validation DWORD $(new-randomString -NumberOfChars 8)" } | Should -not -Throw + { New-JCPolicy -templateID $registryTemplate.id -customRegTable $data -Name "Pester - Registry Validation DWORD $(new-randomString -NumberOfChars 8)" } | Should -Not -Throw $data = @{customData = 'someString'; customLocation = 'location'; customRegType = 'QWORD'; customValueName = 'registryKeyValue' } - { New-JCPolicy -templateID $registryTemplate.id -customRegTable $data -Name "Pester - Registry Validation QWORD $(new-randomString -NumberOfChars 8)" } | Should -not -Throw + { New-JCPolicy -templateID $registryTemplate.id -customRegTable $data -Name "Pester - Registry Validation QWORD $(new-randomString -NumberOfChars 8)" } | Should -Not -Throw $data = @{customData = 'someString'; customLocation = 'location'; customRegType = 'multiString'; customValueName = 'registryKeyValue' } - { New-JCPolicy -templateID $registryTemplate.id -customRegTable $data -Name "Pester - Registry Validation multiString $(new-randomString -NumberOfChars 8)" } | Should -not -Throw + { New-JCPolicy -templateID $registryTemplate.id -customRegTable $data -Name "Pester - Registry Validation multiString $(new-randomString -NumberOfChars 8)" } | Should -Not -Throw $data = @{customData = 'someString'; customLocation = 'location'; customRegType = 'String'; customValueName = 'registryKeyValue' } - { New-JCPolicy -templateID $registryTemplate.id -customRegTable $data -Name "Pester - Registry Validation String $(new-randomString -NumberOfChars 8)" } | Should -not -Throw + { New-JCPolicy -templateID $registryTemplate.id -customRegTable $data -Name "Pester - Registry Validation String $(new-randomString -NumberOfChars 8)" } | Should -Not -Throw $data = @{customData = 'someString'; customLocation = 'location'; customRegType = 'expandString'; customValueName = 'registryKeyValue' } - { New-JCPolicy -templateID $registryTemplate.id -customRegTable $data -Name "Pester - Registry Validation expandString $(new-randomString -NumberOfChars 8)" } | Should -not -Throw + { New-JCPolicy -templateID $registryTemplate.id -customRegTable $data -Name "Pester - Registry Validation expandString $(new-randomString -NumberOfChars 8)" } | Should -Not -Throw } It 'customRegTable param should throw if a list of objects is passed in with an invalid customRegType type' { $registryTemplate = $policyTemplates | Where-Object { $_.name -eq "custom_registry_keys_policy_windows" } @@ -289,7 +289,17 @@ Describe -Tag:('JCPolicy') 'New-JCPolicy' { $usbLinuxPolicy.templateID | Should -Not -BeNullOrEmpty } } - Context 'Manual Test Cases' -skip { + Context 'Create new policy using Registry file' { + It 'New-JCPolicy using regFilePath parameter' { + $registryPolicy = New-JCPolicy -Name 'Pester - RegFileUpload' -templateID '5f07273cb544065386e1ce6f' -registryFile $PesterParams_RegistryFilePath + $registryPolicy.name | Should -Not -BeNullOrEmpty + $registryPolicy.templateID | Should -Be '5f07273cb544065386e1ce6f' + $registryPolicy.values | Should -Not -BeNullOrEmpty + $registryPolicy.id | Should -Not -BeNullOrEmpty + $registryPolicy.template | Should -Not -BeNullOrEmpty + } + } + Context 'Manual Test Cases' -Skip { It 'When you press *tab* after typing the TemplateName parameter, a list of policy templates are generated' { # manual tasks (press tab key in place of *tab*) # type New-JCPolicy -PolicyName *tab* diff --git a/PowerShell/JumpCloud Module/Tests/Public/Policies/Set-JCPolicy.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Policies/Set-JCPolicy.tests.ps1 index 25f341d04..96133047b 100644 --- a/PowerShell/JumpCloud Module/Tests/Public/Policies/Set-JCPolicy.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Policies/Set-JCPolicy.tests.ps1 @@ -3,7 +3,7 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' { . "$($PSSCRIPTROOT)/../../..//Private/Policies/Get-JCPolicyTemplateConfigField.ps1" Connect-JCOnline -JumpCloudApiKey:($PesterParams_ApiKey) -force | Out-Null $policies = Get-JCPolicy - $policies | Where-Object { $_.Name -like "Pester -*" } | % { Remove-JcSdkPolicy -id $_.id } + $policies | Where-Object { $_.Name -like "Pester -*" } | ForEach-Object { Remove-JcSdkPolicy -Id $_.id } $policyTemplates = Get-JcSdkPolicyTemplate } Context 'Sets policies using the dynamic parameter set using the ByID parameter set' { @@ -18,7 +18,7 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' { # update the value with dynamic param $updatedPesterMacStringText = Set-JCPolicy -policyID $PesterMacStringText.id -LoginwindowText $updateText # orig policy def and new policy def should be different - $updatedPesterMacStringText.values.value | Should -not -Be $PesterMacStringText.values.value + $updatedPesterMacStringText.values.value | Should -Not -Be $PesterMacStringText.values.value # updated policy value should be equal to $updateText $updatedPesterMacStringText.values.value | Should -Be $updateText } @@ -26,7 +26,7 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' { $policyTemplate = $policyTemplates | Where-Object { $_.name -eq "lock_screen_darwin" } $templateId = $policyTemplate.id $intValue = 45 - $intPolicy = New-JCPolicy -name "Pester - Integer" -templateID $templateId -timeout $intValue + $intPolicy = New-JCPolicy -Name "Pester - Integer" -templateID $templateId -timeout $intValue $updatedIntValue = 55 $updatedStringPolicy = Set-JCPolicy -policyID $intPolicy.id -timeout $updatedIntValue # Should not be null @@ -70,26 +70,26 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' { $listboxPolicy = New-JCPolicy -Name "Pester - Mac - Encrypted DNS Policy" -templateID $templateId -ServerAddresses "Test Pester Address" -ServerURL "Test URL" -SupplementalMatchDomains "Test Domain" $listboxSet = Set-JCpolicy -policyid $listboxPolicy.Id -ServerAddresses "Test Pester Address1" -ServerURL "Test URL2" -SupplementalMatchDomains "Test Domain3" # set should set the policies to the correct type - ($listboxSet.values | Where-object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.getType() | Should -BeOfType object - ($listboxSet.values | Where-object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.getType() | Should -BeOfType object - ($listboxSet.values | Where-object { $_.ConfigFieldName -eq 'ServerURL' }).value.getType().Name | Should -BeOfType string + ($listboxSet.values | Where-Object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.getType() | Should -BeOfType object + ($listboxSet.values | Where-Object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.getType() | Should -BeOfType object + ($listboxSet.values | Where-Object { $_.ConfigFieldName -eq 'ServerURL' }).value.getType().Name | Should -BeOfType string # since we set only one value the count for each of these objects should be 1 - ($listboxSet.values | Where-object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.count | Should -Be 1 - ($listboxSet.values | Where-object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.count | Should -Be 1 + ($listboxSet.values | Where-Object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.count | Should -Be 1 + ($listboxSet.values | Where-Object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.count | Should -Be 1 # add multiple values here and test $multipleServerAddresses = @("Test Pester Address1", "Test Pester Address2") $multipleSupplementalMatchDomains = @("Test Domain3", "Test Domain4") $listboxSetMultipleValues = Set-JCpolicy -policyid $listboxPolicy.Id -ServerAddresses $multipleServerAddresses -ServerURL "Test URL2" -SupplementalMatchDomains $multipleSupplementalMatchDomains # set should set the policies to the correct type - ($listboxSetMultipleValues.values | Where-object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.getType() | Should -BeOfType object - ($listboxSetMultipleValues.values | Where-object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.getType() | Should -BeOfType object - ($listboxSetMultipleValues.values | Where-object { $_.ConfigFieldName -eq 'ServerURL' }).value.getType().Name | Should -BeOfType string + ($listboxSetMultipleValues.values | Where-Object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.getType() | Should -BeOfType object + ($listboxSetMultipleValues.values | Where-Object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.getType() | Should -BeOfType object + ($listboxSetMultipleValues.values | Where-Object { $_.ConfigFieldName -eq 'ServerURL' }).value.getType().Name | Should -BeOfType string # Count for listbox policy should be 2 - ($listboxSetMultipleValues.values | Where-object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.count | Should -Be 2 - ($listboxSetMultipleValues.values | Where-object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.count | Should -Be 2 + ($listboxSetMultipleValues.values | Where-Object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.count | Should -Be 2 + ($listboxSetMultipleValues.values | Where-Object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.count | Should -Be 2 # validate that the items are correct: - ($listboxSetMultipleValues.values | Where-object { $_.ConfigFieldName -eq 'ServerAddresses' }).value | Should -Be $multipleServerAddresses - ($listboxSetMultipleValues.values | Where-object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value | Should -Be $multipleSupplementalMatchDomains + ($listboxSetMultipleValues.values | Where-Object { $_.ConfigFieldName -eq 'ServerAddresses' }).value | Should -Be $multipleServerAddresses + ($listboxSetMultipleValues.values | Where-Object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value | Should -Be $multipleSupplementalMatchDomains } It 'Sets a policy with a file, dynamic parameter' { @@ -97,8 +97,8 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' { $templateId = $policyTemplate.id # Upload ps1 files for this test - $firstFile = Get-ChildItem $($PSScriptRoot) -Filter *.ps1 | Select -First 1 - $secondFile = Get-ChildItem $($PSScriptRoot) -Filter *.ps1 | Select -Last 1 + $firstFile = Get-ChildItem $($PSScriptRoot) -Filter *.ps1 | Select-Object -First 1 + $secondFile = Get-ChildItem $($PSScriptRoot) -Filter *.ps1 | Select-Object -Last 1 # Add a new policy with file type: @@ -183,7 +183,7 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' { # update the value with dynamic param $updatedPesterMacStringText = Set-JCPolicy -PolicyName $PesterMacStringText.Name -LoginwindowText $updateText # orig policy def and new policy def should be different - $updatedPesterMacStringText.values.value | Should -not -Be $PesterMacStringText.values.value + $updatedPesterMacStringText.values.value | Should -Not -Be $PesterMacStringText.values.value # updated policy value should be equal to $updateText $updatedPesterMacStringText.values.value | Should -Be $updateText } @@ -191,7 +191,7 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' { $policyTemplate = $policyTemplates | Where-Object { $_.name -eq "lock_screen_darwin" } $templateId = $policyTemplate.id $intValue = 45 - $stringPolicy = New-JCPolicy -name "Pester - Integer byName" -templateID $templateId -timeout $intValue + $stringPolicy = New-JCPolicy -Name "Pester - Integer byName" -templateID $templateId -timeout $intValue $updatedIntValue = 55 $updatedStringPolicy = Set-JCPolicy -PolicyName $stringPolicy.Name -timeout $updatedIntValue # Should not be null @@ -235,34 +235,34 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' { $listboxPolicy = New-JCPolicy -Name "Pester - Mac - Encrypted DNS Policy byName" -templateID $templateId -ServerAddresses "Test Pester Address" -ServerURL "Test URL" -SupplementalMatchDomains "Test Domain" $listboxSet = Set-JCpolicy -PolicyName $listboxPolicy.Name -ServerAddresses "Test Pester Address1" -ServerURL "Test URL2" -SupplementalMatchDomains "Test Domain3" # set should set the policies to the correct type - ($listboxSet.values | Where-object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.getType() | Should -BeOfType object - ($listboxSet.values | Where-object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.getType() | Should -BeOfType object - ($listboxSet.values | Where-object { $_.ConfigFieldName -eq 'ServerURL' }).value.getType().Name | Should -BeOfType string + ($listboxSet.values | Where-Object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.getType() | Should -BeOfType object + ($listboxSet.values | Where-Object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.getType() | Should -BeOfType object + ($listboxSet.values | Where-Object { $_.ConfigFieldName -eq 'ServerURL' }).value.getType().Name | Should -BeOfType string # since we set only one value the count for each of these objects should be 1 - ($listboxSet.values | Where-object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.count | Should -Be 1 - ($listboxSet.values | Where-object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.count | Should -Be 1 + ($listboxSet.values | Where-Object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.count | Should -Be 1 + ($listboxSet.values | Where-Object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.count | Should -Be 1 # add multiple values here and test $multipleServerAddresses = @("Test Pester Address1", "Test Pester Address2") $multipleSupplementalMatchDomains = @("Test Domain3", "Test Domain4") $listboxSetMultipleValues = Set-JCpolicy -PolicyName $listboxPolicy.Name -ServerAddresses $multipleServerAddresses -ServerURL "Test URL2" -SupplementalMatchDomains $multipleSupplementalMatchDomains # set should set the policies to the correct type - ($listboxSetMultipleValues.values | Where-object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.getType() | Should -BeOfType object - ($listboxSetMultipleValues.values | Where-object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.getType() | Should -BeOfType object - ($listboxSetMultipleValues.values | Where-object { $_.ConfigFieldName -eq 'ServerURL' }).value.getType().Name | Should -BeOfType string + ($listboxSetMultipleValues.values | Where-Object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.getType() | Should -BeOfType object + ($listboxSetMultipleValues.values | Where-Object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.getType() | Should -BeOfType object + ($listboxSetMultipleValues.values | Where-Object { $_.ConfigFieldName -eq 'ServerURL' }).value.getType().Name | Should -BeOfType string # Count for listbox policy should be 2 - ($listboxSetMultipleValues.values | Where-object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.count | Should -Be 2 - ($listboxSetMultipleValues.values | Where-object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.count | Should -Be 2 + ($listboxSetMultipleValues.values | Where-Object { $_.ConfigFieldName -eq 'ServerAddresses' }).value.count | Should -Be 2 + ($listboxSetMultipleValues.values | Where-Object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value.count | Should -Be 2 # validate that the items are correct: - ($listboxSetMultipleValues.values | Where-object { $_.ConfigFieldName -eq 'ServerAddresses' }).value | Should -Be $multipleServerAddresses - ($listboxSetMultipleValues.values | Where-object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value | Should -Be $multipleSupplementalMatchDomains + ($listboxSetMultipleValues.values | Where-Object { $_.ConfigFieldName -eq 'ServerAddresses' }).value | Should -Be $multipleServerAddresses + ($listboxSetMultipleValues.values | Where-Object { $_.ConfigFieldName -eq 'SupplementalMatchDomains' }).value | Should -Be $multipleSupplementalMatchDomains } It 'Sets a policy with a file, dynamic parameter' { $policyTemplate = $policyTemplates | Where-Object { $_.name -eq "custom_font_policy_darwin" } $templateId = $policyTemplate.id # Upload ps1 files for this test - $firstFile = Get-ChildItem $($PSScriptRoot) -Filter *.ps1 | Select -First 1 - $secondFile = Get-ChildItem $($PSScriptRoot) -Filter *.ps1 | Select -Last 1 + $firstFile = Get-ChildItem $($PSScriptRoot) -Filter *.ps1 | Select-Object -First 1 + $secondFile = Get-ChildItem $($PSScriptRoot) -Filter *.ps1 | Select-Object -Last 1 # Add a new policy with file type: $newFilePolicy = New-JCPolicy -templateID 631f44bc2630c900017ed834 -setFont $firstFile.FullName -Name "Pester - File Test byName" -setName "Roboto Light" @@ -377,7 +377,7 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' { It 'Sets a policy using the values object where a policy has a multi selection type' { $policyTemplate = $policyTemplates | Where-Object { $_.name -eq "system_preferences_panes_darwin" } $templateId = $policyTemplate.id - $valuesSystemPreferenceControl = new-jcpolicy -templateID $templateId -name "Pester - Mac System Preference Control" -pipelineVariable 0 -appstore $false -icloud $true + $valuesSystemPreferenceControl = new-jcpolicy -templateID $templateId -Name "Pester - Mac System Preference Control" -PipelineVariable 0 -appstore $false -icloud $true #Update the values to true $valuesSystemPreferenceControl.values | Where-Object { $_.configFieldName -eq "appstore" } | ForEach-Object { $_.value = $true } $valuesSystemPreferenceControl.values | Where-Object { $_.configFieldName -eq "icloud" } | ForEach-Object { $_.value = $false } @@ -452,7 +452,45 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' { $usbLinuxPolicyUpdated.templateID | Should -Not -BeNullOrEmpty } } - Context 'Manual Test Cases' -skip { + Context 'Validates Throw Conditions' { + It 'Should throw an error when multiple policies with the same name exist and the policyName param is specified' { + $registryTemplate = $policyTemplates | Where-Object { $_.name -eq "disable_usb_storage_linux" } + $randomValue = $(new-randomString -NumberOfChars 8) + $usbLinuxPolicy = New-JCPolicy -TemplateID $registryTemplate.Id -Name "Pester - USB Linux $($randomValue)" + $usbLinuxPolicy = New-JCPolicy -TemplateID $registryTemplate.Id -Name "Pester - USB Linux $($randomValue)" + { Set-JCPolicy -PolicyName -Name "Pester - USB Linux $($randomValue)" -NewName "Pester - USB Linux $(new-randomString -NumberOfChars 8)" } | Should -Throw + + } + } + Context 'Update registry policy using Registry file' { + It 'Set-JCPolicy using regFilePath parameter' { + $registryPolicy = New-JCPolicy -Name "Pester - RegFileUpload $(new-randomString -NumberOfChars 8)" -templateId '5f07273cb544065386e1ce6f' -registryFile $PesterParams_RegistryFilePath + + $NewName = "Pester - RegFileUpload $(new-randomString -NumberOfChars 8)" + + $registryPolicyUpdated = Set-JCPolicy -PolicyID $registryPolicy.Id -NewName $NewName -registryFile $PesterParams_RegistryFilePath + $registryPolicyUpdated.name | Should -Be $NewName + $registryPolicyUpdated.templateID | Should -Be '5f07273cb544065386e1ce6f' + $registryPolicyUpdated.values | Should -Not -BeNullOrEmpty + $registryPolicyUpdated.values.value.count | Should -Be 10 + $registryPolicyUpdated.id | Should -Not -BeNullOrEmpty + $registryPolicyUpdated.template | Should -Not -BeNullOrEmpty + } + It 'Set-JCPolicy using regFilePath parameter and RegisryOverwrite Parameter' { + $registryPolicy = New-JCPolicy -Name "Pester - RegFileUpload $(new-randomString -NumberOfChars 8)" -templateId '5f07273cb544065386e1ce6f' -registryFile $PesterParams_RegistryFilePath + + $NewName = "Pester - RegFileUpload $(new-randomString -NumberOfChars 8)" + + $registryPolicyUpdated = Set-JCPolicy -PolicyID $registryPolicy.Id -NewName $NewName -registryFile $PesterParams_RegistryFilePath -RegistryOverwrite + $registryPolicyUpdated.name | Should -Be $NewName + $registryPolicyUpdated.templateID | Should -Be '5f07273cb544065386e1ce6f' + $registryPolicyUpdated.values | Should -Not -BeNullOrEmpty + $registryPolicyUpdated.values.value.count | Should -Be 5 + $registryPolicyUpdated.id | Should -Not -BeNullOrEmpty + $registryPolicyUpdated.template | Should -Not -BeNullOrEmpty + } + } + Context 'Manual Test Cases' -Skip { # These test cases should be executed locally; Each manual task should be executed when prompted to edit the policy It 'Policy with a string payload can be set interactivly' { # Create a policy @@ -536,10 +574,10 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' { # two rows of data $updatedPolicy.values.value.count | Should -Be 2 # first row of data should have been changed - $updatedPolicy.values.value[0].customData | should -not -be $policyValue.customData - $updatedPolicy.values.value[0].customRegType | should -not -be $policyValue.customRegType - $updatedPolicy.values.value[0].customLocation | should -not -be $policyValue.customLocation - $updatedPolicy.values.value[0].customValueName | should -not -be $policyValue.customValueName + $updatedPolicy.values.value[0].customData | Should -Not -Be $policyValue.customData + $updatedPolicy.values.value[0].customRegType | Should -Not -Be $policyValue.customRegType + $updatedPolicy.values.value[0].customLocation | Should -Not -Be $policyValue.customLocation + $updatedPolicy.values.value[0].customValueName | Should -Not -Be $policyValue.customValueName } } } diff --git a/PowerShell/JumpCloud Module/Tests/Reg_File/PesterRegFile.reg b/PowerShell/JumpCloud Module/Tests/Reg_File/PesterRegFile.reg new file mode 100644 index 000000000..e327cd0d3 Binary files /dev/null and b/PowerShell/JumpCloud Module/Tests/Reg_File/PesterRegFile.reg differ diff --git a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml index 0e63d1bdb..e47168d13 100644 --- a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml +++ b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml @@ -10435,6 +10435,13 @@ PS C:\> New-JCPolicy -TemplateName darwin_Login_Window_Text -Values $policyV This would create a new macOS Login Window Text policy with the login window text set to `Welcome to JumpCloud` with the `macOS - Login Window Policy` name. The policy values are set using the `values` parameter. Objects passed into the `values` parameter set must contain the `value` for the policy config field and a `configFieldID`. To get a policy value object, search for any existing policy using `Get-JCPolicy` the `values` object returned from that cmdlet will contain the config fields required to build new policies or edit existing ones. + + -------------------------- Example 5 -------------------------- + PS C:\> New-JCPolicy -TemplateName windows_Advanced:_Custom_Registry_Keys -Name "Windows - Imported Custom Registry Settings" -RegistryFile "/path/to/registryFile.reg" + + This command would create a new Windows Custom Registry Policy named "Windows - Imported Custom Registry Settings" and populate the values from a registry file. .Reg registry files can be passed into New-JCPolicy as long as the TemplateName is specified with the corresponding "windows_Advanced:_Custom_Registry_Keys" template. .Reg files will be converted and uploaded to the JumpCloud policy as long as they contain "DWORD", "EXPAND_SZ", "MULTI_SZ", "SZ" or "QWORD" type data. + + @@ -15279,6 +15286,20 @@ PS C:\> Set-JCPolicy -PolicyName "macOS - Login Window Policy" -Values $poli This would update the policy named `macOS - Login Window Policy` with the login window text set to `Welcome to JumpCloud`. The policy values are set using the `values` parameter. Objects passed into the `values` parameter set must contain the `value` for the policy config field and a `configFieldID`. To get a policy value object, search for any existing policy using `Get-JCPolicy` the `values` object returned from that cmdlet will contain the config fields required to build new policies or edit existing ones. + + -------------------------- Example 5 -------------------------- + PS C:\> Set-JCPolicy -PolicyName "Windows - Imported Custom Registry Settings" -RegistryFile "/path/to/registryFile.reg" + + This command would append the registry policy's existing values with the imported set of .Reg keys specified by the "RegistryFile" parameter. .Reg files will be converted and uploaded to the JumpCloud policy as long as they contain "DWORD", "EXPAND_SZ", "MULTI_SZ", "SZ" or "QWORD" type data. + + + + -------------------------- Example 6 -------------------------- + PS C:\> Set-JCPolicy -PolicyName "Windows - Imported Custom Registry Settings" -RegistryFile "/path/to/registryFile.reg" -RegistryOverwrite + + This command would overwrite the registry policy's existing values with the imported set of .Reg keys specified by the "RegistryFile" parameter. .Reg files will be converted and uploaded to the JumpCloud policy as long as they contain "DWORD", "EXPAND_SZ", "MULTI_SZ", "SZ" or "QWORD" type data. + + diff --git a/PowerShell/ModuleChangelog.md b/PowerShell/ModuleChangelog.md index 7629d7e9c..3666c586a 100644 --- a/PowerShell/ModuleChangelog.md +++ b/PowerShell/ModuleChangelog.md @@ -1,13 +1,22 @@ -## 2.6.0 +## 2.7.0 -Release Date: June 21, 2023 +Release Date: August 1, 2023 #### RELEASE NOTES ``` -Update/Import-JCMspFromCSV functions added. +This release introduces a new parameter, registryFile, to New-JCPolicy and Set-JCPolicy ``` +#### FEATURES: + +Admins can now upload a .reg file to a new or existing Windows - Advanced: Custom Registry Keys Policy + +### BUG FIXES: + +Fixed an issue with sequential results not returning as expected with large datasets + + ## 2.5.1 Release Date: May 30, 2023