From ced5c1f326de78d29da85b3c7fcc77f6bf451381 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Mon, 12 Jun 2023 11:16:55 -0600 Subject: [PATCH 01/77] Create Convert-RegToPSObject.ps1 --- .../JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 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..e69de29bb From 5221440d3046694c662fc022af1300cc60faf5e0 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Tue, 13 Jun 2023 14:00:09 -0600 Subject: [PATCH 02/77] Update Convert-RegToPSObject.ps1 --- .../Policies/Convert-RegToPSObject.ps1 | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 b/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 index e69de29bb..8ad54537c 100644 --- a/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 +++ b/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 @@ -0,0 +1,98 @@ +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 = "HKLM:" + ($line.TrimStart("[").TrimEnd("]")).Replace("HKEY_LOCAL_MACHINE", "").Replace("\\\\", "\\") + } + } else { + # Extract Values + if ($line.Contains("=")) { + $valueObject = $($line.Split("=")).Trim("`"") + $valueName = $($valueObject[0]).Trim() + if ($valueObject[1].StartsWith("dword:")) { + #DWORD + $customRegType = "DWORD" + $customData = ($valueObject[1]).Substring(5) + } 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] } + $customData = '0x' + ($value -join "").trimstart('0') + } 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 From 4bdb82eb1b3a137af81d41de2d4151b939d068fa Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Wed, 14 Jun 2023 10:36:23 -0600 Subject: [PATCH 03/77] Convert hex value to int --- .../Private/Policies/Convert-RegToPSObject.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 b/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 index 8ad54537c..6713ba36f 100644 --- a/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 +++ b/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 @@ -54,7 +54,8 @@ function Convert-RegToPSObject { $value = ($valueObject[1]).Substring(7).split(",") # Convert to value $value = for ($i = $value.count - 1; $i -ge 0; $i--) { $value[$i] } - $customData = '0x' + ($value -join "").trimstart('0') + $hexValue = '0x' + ($value -join "").trimstart('0') + $customData = [int]$hexValue } elseif ($valueObject[1].StartsWith("hex(7):")) { #MULTI_SZ $customRegType = "multiString" From 6b42d18ed640c0828f3362595328cac9b625224c Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Thu, 15 Jun 2023 13:48:13 -0600 Subject: [PATCH 04/77] remove HKLM --- .../JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 b/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 index 6713ba36f..b19e1727e 100644 --- a/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 +++ b/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 @@ -37,7 +37,7 @@ function Convert-RegToPSObject { if ($line -notmatch "HKEY_LOCAL_MACHINE") { throw "JumpCloud Policies only support HKEY_LOCAL_MACHINE/HKLM registry keys" } else { - $path = "HKLM:" + ($line.TrimStart("[").TrimEnd("]")).Replace("HKEY_LOCAL_MACHINE", "").Replace("\\\\", "\\") + $path = $line.TrimStart("[").TrimEnd("]").Replace("HKEY_LOCAL_MACHINE", "").Replace("\\\\", "\\").TrimStart('\') } } else { # Extract Values From 351d540949536bfd3084ee5764258afddc90be8d Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Thu, 15 Jun 2023 13:48:22 -0600 Subject: [PATCH 05/77] ParameterSets --- .../Public/Policies/New-JCPolicy.ps1 | 425 ++++++++++-------- 1 file changed, 227 insertions(+), 198 deletions(-) diff --git a/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 b/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 index 7eb1df5e9..d80b0cb04 100644 --- a/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 +++ b/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 @@ -5,101 +5,112 @@ function New-JCPolicy { ParameterSetName = 'ByID', ValueFromPipelineByPropertyName = $true, HelpMessage = 'The ID of the policy template to create as a new JumpCloud Policy')] + [Parameter(ParameterSetName = 'Standard')] [System.String] $TemplateID, [Parameter(Mandatory = $true, ParameterSetName = 'ByName', HelpMessage = 'The Name of the policy template to create as a new JumpCloud Policy')] + [Parameter(ParameterSetName = 'Standard')] [System.String] $TemplateName, [Parameter(Mandatory = $false, HelpMessage = 'The name of the policy to create. If left unspecified, the cmdlet will attempt to create the policy with the default name defined by the selected policy template.')] + [Parameter(ParameterSetName = 'Standard')] + [Parameter(ParameterSetName = 'RegistryFile')] [System.String] $Name, [Parameter(ValueFromPipelineByPropertyName = $true, HelpMessage = 'The values object either built manually or passed in through Get-JCPolicy')] + [Parameter(ParameterSetName = 'Standard')] [System.object[]] - $Values + $Values, + [Parameter(Mandatory = $false, + ParameterSetName = 'RegistryFile', + HelpMessage = 'A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template.')] + [System.IO.FileInfo]$registryFile ) DynamicParam { - if ($PSBoundParameters["TemplateID"]) { - $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute - $ParameterAttribute.Mandatory = $false - $ParameterAttribute.ParameterSetName = "ByID" - # Get the policy template by ID - $templateObject = Get-JCPolicyTemplateConfigField -templateID $templateID - if ([String]::IsNullOrEmpty($templateObject.defaultName)) { - throw "Could not find policy template by ID" - } + if ($PSCmdlet.ParameterSetName -eq "Standard") { + if ($PSBoundParameters["TemplateID"]) { + $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute + $ParameterAttribute.Mandatory = $false + $ParameterAttribute.ParameterSetName = "ByID" + # Get the policy template by ID + $templateObject = Get-JCPolicyTemplateConfigField -templateID $templateID + if ([String]::IsNullOrEmpty($templateObject.defaultName)) { + throw "Could not find policy template by ID" + } - } elseif ($PSBoundParameters["TemplateName"]) { - $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute - $ParameterAttribute.Mandatory = $false - $ParameterAttribute.ParameterSetName = "ByName" - # Get the policy by Name - if ($TemplateName -in $global:TemplateNameList.Name) { - $matchedTemplate = $templateNameList[$templateNameList.Name.IndexOf($TemplateName)].id - } else { - throw "template list missing; have you run Connect-JCOnline" - } - $templateObject = Get-JCPolicyTemplateConfigField -templateID $matchedTemplate - if ([String]::IsNullOrEmpty($templateObject.defaultName)) { - throw "Could not find policy template by specified Name" + } elseif ($PSBoundParameters["TemplateName"]) { + $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute + $ParameterAttribute.Mandatory = $false + $ParameterAttribute.ParameterSetName = "ByName" + # Get the policy by Name + if ($TemplateName -in $global:TemplateNameList.Name) { + $matchedTemplate = $templateNameList[$templateNameList.Name.IndexOf($TemplateName)].id + } else { + throw "template list missing; have you run Connect-JCOnline" + } + $templateObject = Get-JCPolicyTemplateConfigField -templateID $matchedTemplate + if ([String]::IsNullOrEmpty($templateObject.defaultName)) { + throw "Could not find policy template by specified Name" + } } - } - if ($templateObject.objectMap -And ($PSBoundParameters["TemplateName"] -OR $PSBoundParameters["TemplateID"])) { - $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary - # Foreach key in the supplied config file: - foreach ($key in $templateObject.objectMap) { - # Set the dynamic parameters' name - $ParamName_Filter = "$($key.configFieldName)" - # Create the collection of attributes - $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] - # If ValidateSet is specified in the config file, set the value here: - # If the type of value is a bool, create a custom validateSet attribute here: - $paramType = $($key.type) - switch ($paramType) { - 'boolean' { - $arrSet = @("true", "false") - $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) - $AttributeCollection.Add($ValidateSetAttribute) - } - 'multi' { - $paramType = 'string' - $arrSet = $key.validation.values - $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) - $AttributeCollection.Add($ValidateSetAttribute) - } - 'file' { - $paramType = 'string' - } - 'listbox' { - $paramType = [system.string[]] - } - 'table' { - $paramType = [system.object[]] - } - 'exclude' { - Continue + if ($templateObject.objectMap -And ($PSBoundParameters["TemplateName"] -OR $PSBoundParameters["TemplateID"])) { + $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary + # Foreach key in the supplied config file: + foreach ($key in $templateObject.objectMap) { + # Set the dynamic parameters' name + $ParamName_Filter = "$($key.configFieldName)" + # Create the collection of attributes + $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] + # If ValidateSet is specified in the config file, set the value here: + # If the type of value is a bool, create a custom validateSet attribute here: + $paramType = $($key.type) + switch ($paramType) { + 'boolean' { + $arrSet = @("true", "false") + $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) + $AttributeCollection.Add($ValidateSetAttribute) + } + 'multi' { + $paramType = 'string' + $arrSet = $key.validation.values + $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) + $AttributeCollection.Add($ValidateSetAttribute) + } + 'file' { + $paramType = 'string' + } + 'listbox' { + $paramType = [system.string[]] + } + 'table' { + $paramType = [system.object[]] + } + 'exclude' { + Continue + } + Default { + $paramType = 'string' + } } - Default { - $paramType = 'string' + if ([String]::isNullorEmpty($($key.help))) { + $ParameterAttribute.HelpMessage = "sets the value for the $($key.name) field" + } else { + $ParameterAttribute.HelpMessage = "$($key.help)" } + # Add the attributes to the attributes collection + $AttributeCollection.Add($ParameterAttribute) + # Add the param + $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParamName_Filter, $paramType, $AttributeCollection) + $RuntimeParameterDictionary.Add($ParamName_Filter, $RuntimeParameter) } - if ([String]::isNullorEmpty($($key.help))) { - $ParameterAttribute.HelpMessage = "sets the value for the $($key.name) field" - } else { - $ParameterAttribute.HelpMessage = "$($key.help)" - } - # Add the attributes to the attributes collection - $AttributeCollection.Add($ParameterAttribute) - # Add the param - $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParamName_Filter, $paramType, $AttributeCollection) - $RuntimeParameterDictionary.Add($ParamName_Filter, $RuntimeParameter) + # Returns the dictionary + return $RuntimeParameterDictionary } - # Returns the dictionary - return $RuntimeParameterDictionary } } begin { @@ -109,154 +120,172 @@ function New-JCPolicy { } } process { - $params = $PSBoundParameters - $paramterSet = $params.keys - $DynamicParamSet = $false - $requiredSet = @('TemplateID', 'TemplateName', 'Name' , 'Values') - foreach ($parameter in $paramterSet) { - $parameterComparison = Compare-Object -ReferenceObject $requiredSet -DifferenceObject $parameter - if ($parameterComparison | Where-Object { $_.sideindicator -eq "=>" }) { - $DynamicParamSet = $true - break + if ($PSCmdlet.ParameterSetName -eq "Standard") { + $params = $PSBoundParameters + $paramterSet = $params.keys + $DynamicParamSet = $false + $requiredSet = @('TemplateID', 'TemplateName', 'Name' , 'Values') + foreach ($parameter in $paramterSet) { + $parameterComparison = Compare-Object -ReferenceObject $requiredSet -DifferenceObject $parameter + if ($parameterComparison | Where-Object { $_.sideindicator -eq "=>" }) { + $DynamicParamSet = $true + break + } } - } - # If TemplateName was specified get ID from hashed table - if ($PSBoundParameters["TemplateName"]) { - if ($TemplateName -in $templateNameList.Name) { - $TemplateID = $templateNameList[$templateNameList.Name.IndexOf($TemplateName)].id + # If TemplateName was specified get ID from hashed table + if ($PSBoundParameters["TemplateName"]) { + if ($TemplateName -in $templateNameList.Name) { + $TemplateID = $templateNameList[$templateNameList.Name.IndexOf($TemplateName)].id + } else { + throw "The template name: `"$templateName`" was not found in the list of available template names. To find the list of avaiable template names, type `"New-JCPolcy -TemplateName ` and press the tab key. If prompted, press `"y`" to view all availbale templates. Templates start with os type. To find the list of avaiable windows template names, type `"New-JCPolcy -TemplateName windows`" and press the tab key. To find the list of avaiable darwin template names, type `"New-JCPolcy -TemplateName darwin`" and press the tab key. To find the list of avaiable linux template names, type `"New-JCPolcy -TemplateName linux`" and press the tab key." + } + } + $templateObject = Get-JCPolicyTemplateConfigField -templateID $templateID + $policyName = if ($PSBoundParameters["name"]) { + $Name } else { - throw "The template name: `"$templateName`" was not found in the list of available template names. To find the list of avaiable template names, type `"New-JCPolcy -TemplateName ` and press the tab key. If prompted, press `"y`" to view all availbale templates. Templates start with os type. To find the list of avaiable windows template names, type `"New-JCPolcy -TemplateName windows`" and press the tab key. To find the list of avaiable darwin template names, type `"New-JCPolcy -TemplateName darwin`" and press the tab key. To find the list of avaiable linux template names, type `"New-JCPolcy -TemplateName linux`" and press the tab key." + $templateObject.defaultName } - } - $templateObject = Get-JCPolicyTemplateConfigField -templateID $templateID - $policyName = if ($PSBoundParameters["name"]) { - $Name - } else { - $templateObject.defaultName - } - if ($DynamicParamSet) { - $newObject = New-Object System.Collections.ArrayList - for ($i = 0; $i -lt $templateObject.objectMap.count; $i++) { - # If one of the dynamicParam config fields are passed in and is found in the policy template, set the new value: - if ($templateObject.objectMap[$i].configFieldName -in $params.keys) { - $keyName = $params.keys | Where-Object { $_ -eq $templateObject.objectMap[$i].configFieldName } - $keyValue = $params.$KeyName - # write-host "Setting value from $($keyName) $($KeyValue)" - switch ($templateObject.objectMap[$i].type) { - 'multi' { - $templateObject.objectMap[$i].value = $(($templateObject.objectMap[$i].validation | Where-Object { $_.Values -eq $keyValue }).keys) - $templateObject.objectMap[$i].value = $(($templateObject.objectMap[$i].validation | Where-Object { $_.Values -eq $keyValue }).keys) - } - 'file' { - $path = Test-Path -Path $keyValue - if ($path) { - # convert file path to base64 string - $templateObject.objectMap[$i].value = [convert]::ToBase64String((Get-Content -Path $keyValue -AsByteStream)) + if ($DynamicParamSet) { + $newObject = New-Object System.Collections.ArrayList + for ($i = 0; $i -lt $templateObject.objectMap.count; $i++) { + # If one of the dynamicParam config fields are passed in and is found in the policy template, set the new value: + if ($templateObject.objectMap[$i].configFieldName -in $params.keys) { + $keyName = $params.keys | Where-Object { $_ -eq $templateObject.objectMap[$i].configFieldName } + $keyValue = $params.$KeyName + # write-host "Setting value from $($keyName) $($KeyValue)" + switch ($templateObject.objectMap[$i].type) { + 'multi' { + $templateObject.objectMap[$i].value = $(($templateObject.objectMap[$i].validation | Where-Object { $_.Values -eq $keyValue }).keys) + $templateObject.objectMap[$i].value = $(($templateObject.objectMap[$i].validation | Where-Object { $_.Values -eq $keyValue }).keys) } - } - 'listbox' { - if ($($keyValue).getType().name -eq 'String') { - # Given case for single string passed in as dynamic input, convert to a list - $listRows = New-Object System.Collections.ArrayList - foreach ($regItem in $keyValue) { - $listRows.Add($regItem) | Out-Null + 'file' { + $path = Test-Path -Path $keyValue + if ($path) { + # convert file path to base64 string + $templateObject.objectMap[$i].value = [convert]::ToBase64String((Get-Content -Path $keyValue -AsByteStream)) } - $templateObject.objectMap[$i].value = $listRows - } elseif ($($keyValue).getType().name -eq 'Object[]') { - # else if the object passed in is a list already, pass in list - $templateObject.objectMap[$i].value = $($keyValue) } - } - 'table' { - # For custom registry table, validate the object - if ($templateObject.objectMap[$i].configFieldName -eq "customRegTable") { - # get default value properties - $RegProperties = $templateObject.objectMap[$i].defaultValue | Get-Member -MemberType NoteProperty - # get passed in object properties - $ObjectProperties = if ($keyValue | Get-Member -MemberType NoteProperty) { - # for lists get note properties - ($keyValue | Get-Member -MemberType NoteProperty).Name - } else { - # for single objects, get keys - $keyValue.keys - } - $RegProperties | ForEach-Object { - if ($_.Name -notin $ObjectProperties) { - Throw "Custom Registry Tables require a `"$($_.Name)`" data string. The following data types were found: $($ObjectProperties)" + 'listbox' { + if ($($keyValue).getType().name -eq 'String') { + # Given case for single string passed in as dynamic input, convert to a list + $listRows = New-Object System.Collections.ArrayList + foreach ($regItem in $keyValue) { + $listRows.Add($regItem) | Out-Null } + $templateObject.objectMap[$i].value = $listRows + } elseif ($($keyValue).getType().name -eq 'Object[]') { + # else if the object passed in is a list already, pass in list + $templateObject.objectMap[$i].value = $($keyValue) } - # reg type validation - $validRegTypes = @('DWORD', 'expandString', 'multiString', 'QWORD', 'String') - $($keyValue).customRegType | ForEach-Object { - if ($_ -notin $validRegTypes) { - throw "Custom Registry Tables require the `"customRegType`" data string to be one of: $validRegTypes, found: $_" + } + 'table' { + # For custom registry table, validate the object + if ($templateObject.objectMap[$i].configFieldName -eq "customRegTable") { + # get default value properties + $RegProperties = $templateObject.objectMap[$i].defaultValue | Get-Member -MemberType NoteProperty + # get passed in object properties + $ObjectProperties = if ($keyValue | Get-Member -MemberType NoteProperty) { + # for lists get note properties + ($keyValue | Get-Member -MemberType NoteProperty).Name + } else { + # for single objects, get keys + $keyValue.keys + } + $RegProperties | ForEach-Object { + if ($_.Name -notin $ObjectProperties) { + Throw "Custom Registry Tables require a `"$($_.Name)`" data string. The following data types were found: $($ObjectProperties)" + } + } + # reg type validation + $validRegTypes = @('DWORD', 'expandString', 'multiString', 'QWORD', 'String') + $($keyValue).customRegType | ForEach-Object { + if ($_ -notin $validRegTypes) { + throw "Custom Registry Tables require the `"customRegType`" data string to be one of: $validRegTypes, found: $_" + } } } + $regRows = New-Object System.Collections.ArrayList + foreach ($regItem in $keyValue) { + $regRows.Add($regItem) | Out-Null + } + $templateObject.objectMap[$i].value = $regRows } - $regRows = New-Object System.Collections.ArrayList - foreach ($regItem in $keyValue) { - $regRows.Add($regItem) | Out-Null + Default { + $templateObject.objectMap[$i].value = $($keyValue) } - $templateObject.objectMap[$i].value = $regRows } - Default { - $templateObject.objectMap[$i].value = $($keyValue) + $newObject.Add($templateObject.objectMap[$i]) | 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 + $newObject.Add($templateObject.objectMap[$i]) | Out-Null + } + } + $updatedPolicyObject = $newObject | Select-Object configFieldID, configFieldName, value + } elseif ($values) { + $updatedPolicyObject = $values + } else { + if (($templateObject.objectMap).count -gt 0) { + $initialUserInput = Show-JCPolicyValues -policyObject $templateObject.objectMap + # User selects edit all fields + if ($initialUserInput.fieldSelection -eq 'A') { + for ($i = 0; $i -le $initialUserInput.fieldCount; $i++) { + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $i } + # Display policy values + Show-JCPolicyValues -policyObject $updatedPolicyObject -ShowTable $true } - $newObject.Add($templateObject.objectMap[$i]) | 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 - $newObject.Add($templateObject.objectMap[$i]) | Out-Null + # User selects edit individual field + elseif ($initialUserInput.fieldSelection -ne 'C' -or $initialUserInput.fieldSelection -ne 'A') { + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $initialUserInput.fieldSelection + Do { + # Hide option to edit all fields + $userInput = Show-JCPolicyValues -policyObject $updatedPolicyObject -HideAll $true + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $userInput.fieldSelection + } while ($userInput.fieldSelection -ne 'C') + } + $updatedPolicyObject = $updatedPolicyObject | Select-Object configFieldID, configFieldName, value } } - $updatedPolicyObject = $newObject | Select-Object configFieldID, configFieldName, value - } elseif ($values) { - $updatedPolicyObject = $values - } else { - if (($templateObject.objectMap).count -gt 0) { - $initialUserInput = Show-JCPolicyValues -policyObject $templateObject.objectMap - # User selects edit all fields - if ($initialUserInput.fieldSelection -eq 'A') { - for ($i = 0; $i -le $initialUserInput.fieldCount; $i++) { - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $i + + # Validate PolicyObject + if ($updatedPolicyObject) { + $updatedPolicyObject | ForEach-Object { + # Check to see if value property is set, if not set to defaultValue + if ($_.value -eq $null) { + $_.value = $_.defaultValue } - # Display policy values - Show-JCPolicyValues -policyObject $updatedPolicyObject -ShowTable $true } - # User selects edit individual field - elseif ($initialUserInput.fieldSelection -ne 'C' -or $initialUserInput.fieldSelection -ne 'A') { - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $initialUserInput.fieldSelection - Do { - # Hide option to edit all fields - $userInput = Show-JCPolicyValues -policyObject $updatedPolicyObject -HideAll $true - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $userInput.fieldSelection - } while ($userInput.fieldSelection -ne 'C') - } - $updatedPolicyObject = $updatedPolicyObject | Select-Object configFieldID, configFieldName, value - } - } + $body = [PSCustomObject]@{ + name = $policyName + template = @{id = $templateID } + values = @($updatedPolicyObject) + } | ConvertTo-Json -Depth 99 + } else { + # for policies w/o payloads, just pass in the name & template + $body = [PSCustomObject]@{ + name = $policyName + template = @{id = $templateID } + } | ConvertTo-Json -Depth 99 - # Validate PolicyObject - if ($updatedPolicyObject) { - $updatedPolicyObject | ForEach-Object { - # Check to see if value property is set, if not set to defaultValue - if ($_.value -eq $null) { - $_.value = $_.defaultValue + } + } elseif ($PSCmdlet.ParameterSetName -eq 'RegistryFile') { + $regKeys = Convert-RegToPSObject -regFilePath $registryFile + $body = @{ + "name" = if (!$Name) { "Advanced: Custom Registry Keys" } else { $($Name) } + "values" = @(@{ + "configFieldID" = '5f07273cb544065386e1ce70' + "configFieldName" = 'customRegTable' + "sensitive" = $($false) + "value" = @($regKeys) + }) + "template" = @{ + "id" = "5f07273cb544065386e1ce6f" } } - $body = [PSCustomObject]@{ - name = $policyName - template = @{id = $templateID } - values = @($updatedPolicyObject) - } | ConvertTo-Json -Depth 99 - } else { - # for policies w/o payloads, just pass in the name & template - $body = [PSCustomObject]@{ - name = $policyName - template = @{id = $templateID } - } | ConvertTo-Json -Depth 99 - + $body = ConvertTo-Json -InputObject $body -Depth 10 + Write-Debug $Body } $headers = @{ 'x-api-key' = $env:JCApiKey From fab9dd6968e999bc46bb6f1e54fc4fc3ef36c93d Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Tue, 20 Jun 2023 11:25:26 -0600 Subject: [PATCH 06/77] registryFile --- .../Public/Policies/Set-JCPolicy.ps1 | 62 ++++++++++++------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 index f45d0b239..7b3e48f99 100644 --- a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 +++ b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 @@ -22,7 +22,11 @@ function Set-JCPolicy { [Parameter(ValueFromPipelineByPropertyName = $true, HelpMessage = 'The values object either built manually or passed in through Get-JCPolicy')] [System.object[]] - $Values + $Values, + [Parameter(Mandatory = $false, + ParameterSetName = 'RegistryFile', + HelpMessage = 'A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template.')] + [System.IO.FileInfo]$registryFile ) DynamicParam { @@ -215,6 +219,11 @@ function Set-JCPolicy { } } $updatedPolicyObject = $newObject | Select-Object configFieldID, configFieldName, value + if ($registryFile) { + $regKeys = Convert-RegToPSObject -regFilePath $registryFile + $updatedPolicyObject.value += $regKeys + Write-Debug $updatedPolicyObject + } } elseif ($values) { # begin value param set $updatedPolicyObject = New-Object System.Collections.ArrayList @@ -230,31 +239,38 @@ function Set-JCPolicy { } } else { if (($templateObject.objectMap).count -gt 0) { - # Begin user prompt - $initialUserInput = Show-JCPolicyValues -policyObject $templateObject.objectMap -policyValues $foundPolicy.values - # User selects edit all fields - if ($initialUserInput.fieldSelection -eq 'A') { - for ($i = 0; $i -le $initialUserInput.fieldCount; $i++) { - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $i -policyValues $foundPolicy.values + if ($registryFile) { + $updatedPolicyObject = $foundPolicy.values + $regKeys = Convert-RegToPSObject -regFilePath $registryFile + $updatedPolicyObject.value += $regKeys + Write-Debug $updatedPolicyObject + } else { + # Begin user prompt + $initialUserInput = Show-JCPolicyValues -policyObject $templateObject.objectMap -policyValues $foundPolicy.values + # User selects edit all fields + if ($initialUserInput.fieldSelection -eq 'A') { + for ($i = 0; $i -le $initialUserInput.fieldCount; $i++) { + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $i -policyValues $foundPolicy.values + } + # Display policy values + # Show-JCPolicyValues -policyObject $updatedPolicyObject -ShowTable $true } - # Display policy values - # Show-JCPolicyValues -policyObject $updatedPolicyObject -ShowTable $true - } - # User selects edit individual field - elseif ($initialUserInput.fieldSelection -ne 'C' -or $initialUserInput.fieldSelection -ne 'A') { - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $initialUserInput.fieldSelection -policyValues $foundPolicy.values - # For set-jcpolicy, add the help & label options - $updatedPolicyObject | ForEach-Object { - if ($_.configFieldID -in $templateObject.objectMap.configFieldID) { - $_ | Add-Member -MemberType NoteProperty -Name "help" -Value $templateObject.objectMap[$templateObject.objectMap.configFieldID.IndexOf($($_.configFieldID))].help - $_ | Add-Member -MemberType NoteProperty -Name "label" -Value $templateObject.objectMap[$templateObject.objectMap.configFieldID.IndexOf($($_.configFieldID))].label + # User selects edit individual field + elseif ($initialUserInput.fieldSelection -ne 'C' -or $initialUserInput.fieldSelection -ne 'A') { + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $initialUserInput.fieldSelection -policyValues $foundPolicy.values + # For set-jcpolicy, add the help & label options + $updatedPolicyObject | ForEach-Object { + if ($_.configFieldID -in $templateObject.objectMap.configFieldID) { + $_ | Add-Member -MemberType NoteProperty -Name "help" -Value $templateObject.objectMap[$templateObject.objectMap.configFieldID.IndexOf($($_.configFieldID))].help + $_ | Add-Member -MemberType NoteProperty -Name "label" -Value $templateObject.objectMap[$templateObject.objectMap.configFieldID.IndexOf($($_.configFieldID))].label + } } + Do { + # Hide option to edit all fields + $userInput = Show-JCPolicyValues -policyObject $updatedPolicyObject -HideAll $true -policyValues $foundPolicy.values + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $userInput.fieldSelection -policyValues $foundPolicy.values + } while ($userInput.fieldSelection -ne 'C') } - Do { - # Hide option to edit all fields - $userInput = Show-JCPolicyValues -policyObject $updatedPolicyObject -HideAll $true -policyValues $foundPolicy.values - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $userInput.fieldSelection -policyValues $foundPolicy.values - } while ($userInput.fieldSelection -ne 'C') } } } From 262918d75aea5ecc552140a117e8484a151c66ec Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Wed, 21 Jun 2023 13:46:39 -0600 Subject: [PATCH 07/77] tests --- .../Policies/Convert-RegToPSObject.Tests.ps1 | 17 ++++ .../Public/Policies/New-JCPolicy.tests.ps1 | 83 +++++++++------- .../Public/Policies/Set-JCPolicy.tests.ps1 | 94 ++++++++++-------- .../Tests/Reg_File/PesterRegFile.reg | Bin 0 -> 768 bytes 4 files changed, 119 insertions(+), 75 deletions(-) create mode 100644 PowerShell/JumpCloud Module/Tests/Private/Policies/Convert-RegToPSObject.Tests.ps1 create mode 100644 PowerShell/JumpCloud Module/Tests/Reg_File/PesterRegFile.reg 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..721589962 --- /dev/null +++ b/PowerShell/JumpCloud Module/Tests/Private/Policies/Convert-RegToPSObject.Tests.ps1 @@ -0,0 +1,17 @@ +BeforeAll { + $PesterRegistryFilePath = "$PSScriptRoot/Private/Policies/Reg_File/PesterRegFile.reg" +} +Describe -Tag:('JCPolicy') 'Registry File Tests' { + + Context 'Test Reg File Conversion' { + $regFile = Convert-RegToPSObject -regFilePath $PesterRegistryFilePath + 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 + } + } + } +} \ 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..4b1e214c8 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,18 @@ 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' { + $PesterRegistryFilePath = "$PSScriptRoot/Reg_File/PesterRegFile.reg" + $registryPolicy = New-JCPolicy -Name 'Pester - RegFileUpload' -registryFile $PesterRegistryFilePath + $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..df6176e62 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,23 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' { $usbLinuxPolicyUpdated.templateID | Should -Not -BeNullOrEmpty } } - Context 'Manual Test Cases' -skip { + Context 'Update registry policy using Registry file' { + It 'Set-JCPolicy using regFilePath parameter' { + $PesterRegistryFilePath = "$PSScriptRoot/Reg_File/PesterRegFile.reg" + $registryPolicy = New-JCPolicy -Name "Pester - RegFileUpload $(new-randomString -NumberOfChars 8)" -registryFile $PesterRegistryFilePath + + $NewName = "Pester - RegFileUpload $(new-randomString -NumberOfChars 8)" + + $registryPolicyUpdated = Set-JCPolicy -PolicyID $registryPolicy.Id -NewName $NewName -registryFile $PesterRegistryFilePath + $registryPolicyUpdated.name | Should -Be $NewName + $registryPolicyUpdated.templateID | Should -Be '5f07273cb544065386e1ce6f' + $registryPolicyUpdated.values | Should -Not -BeNullOrEmpty + $registryPolicyUpdated.values.value.count | Should -Be 8 + $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 +552,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 0000000000000000000000000000000000000000..4a7bca14437aa6a3f20632363a524875c01331be GIT binary patch literal 768 zcmb`FTTjA35QWdPiT{E0NfR+jDHIbQ2w*f`P>SNEhG@A+qL5G&{qyR#TT6M-@L-zl z%$%7$JF{oMK06v|tez&CD^^Y|^)&>GHPcidAPur3q6u+MSLCN;N5o@dPutqzTi2Rh zcRJKDdv4U#iJGdZitXwYTO)U*GqRxqatCUw1KzU8IgHQnMyx(3gzPcV6g*}P=pmG; zn%f?h{QzXfXJ#2veQ$elbOC=8{yKd>!2U{|qkTPL-?gDfZE8=u^uJ}NSmkdfb?EJq zx!TMV==K-(vSs&FT(Fn8uk?(v+$BG&ap@-3m&0f`dYsMxDjWB literal 0 HcmV?d00001 From cb9b778af3e69e52a22c06299dee7c88046290a8 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Thu, 22 Jun 2023 17:43:38 +0000 Subject: [PATCH 08/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/Docs/JumpCloud.md | 2 +- .../JumpCloud Module/Docs/New-JCPolicy.md | 64 +++++++- .../JumpCloud Module/Docs/Set-JCPolicy.md | 20 +++ .../Docs/Set-JCSettingsFile.md | 2 +- PowerShell/JumpCloud Module/JumpCloud.psd1 | 4 +- .../JumpCloud Module/en-Us/JumpCloud-help.xml | 155 +++++++++++++++++- PowerShell/ModuleChangelog.md | 22 +++ 7 files changed, 263 insertions(+), 6 deletions(-) diff --git a/PowerShell/JumpCloud Module/Docs/JumpCloud.md b/PowerShell/JumpCloud Module/Docs/JumpCloud.md index 567121a0f..935ba2a34 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.5.1 +Help Version: 2.6.1 Locale: en-US --- diff --git a/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md b/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md index 0c5eb8b6f..c867cfb97 100644 --- a/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md +++ b/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md @@ -22,11 +22,22 @@ At a minimum to display the dynamic set of parameters per template, the `Templat New-JCPolicy -TemplateID [-Name ] [-Values ] [] ``` +### Standard +``` +New-JCPolicy [-TemplateID ] [-TemplateName ] [-Name ] [-Values ] + [] +``` + ### ByName ``` New-JCPolicy -TemplateName [-Name ] [-Values ] [] ``` +### RegistryFile +``` +New-JCPolicy [-Name ] [-Values ] [-registryFile ] [] +``` + ## DESCRIPTION New-JCPolicy allows for the creation of new JumpCloud Policies via the JumpCloud PowerShell Module. @@ -90,6 +101,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -registryFile +A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template. + +```yaml +Type: System.IO.FileInfo +Parameter Sets: RegistryFile +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -TemplateID The ID of the policy template to create as a new JumpCloud Policy @@ -106,10 +132,34 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +```yaml +Type: System.String +Parameter Sets: Standard +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + ### -TemplateName The Name of the policy template to create as a new JumpCloud Policy +```yaml +Type: System.String +Parameter Sets: Standard +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ```yaml Type: System.String Parameter Sets: ByName @@ -128,7 +178,19 @@ The values object either built manually or passed in through Get-JCPolicy ```yaml Type: System.Object[] -Parameter Sets: (All) +Parameter Sets: ByID, ByName, RegistryFile +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +```yaml +Type: System.Object[] +Parameter Sets: Standard Aliases: Required: False diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md b/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md index 5e2ff89fa..156ac90f7 100644 --- a/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md +++ b/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md @@ -27,6 +27,11 @@ Set-JCPolicy -PolicyID [-NewName ] [-Values ] [ [-NewName ] [-Values ] [] ``` +### RegistryFile +``` +Set-JCPolicy [-NewName ] [-Values ] [-registryFile ] [] +``` + ## DESCRIPTION Set-JCPolicy allows for the update of existing JumpCloud Policies via the JumpCloud PowerShell Module. @@ -122,6 +127,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -registryFile +A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template. + +```yaml +Type: System.IO.FileInfo +Parameter Sets: RegistryFile +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Values The values object either built manually or passed in through Get-JCPolicy diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md b/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md index ba6b37a0c..f8bf10130 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 [-moduleBannerMessageCount ] [-parallelOverride ] [] +Set-JCSettingsFile [-parallelOverride ] [-moduleBannerMessageCount ] [] ``` ## DESCRIPTION diff --git a/PowerShell/JumpCloud Module/JumpCloud.psd1 b/PowerShell/JumpCloud Module/JumpCloud.psd1 index 9da628246..309882f0b 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: 5/30/2023 +# Generated on: 6/22/2023 # @{ @@ -12,7 +12,7 @@ RootModule = 'JumpCloud.psm1' # Version number of this module. -ModuleVersion = '2.5.1' +ModuleVersion = '2.6.1' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml index 92bb0cfd6..db3ce8f66 100644 --- a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml +++ b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml @@ -9986,6 +9986,45 @@ SystemID CommandID Status New-JCPolicy allows for the creation of new JumpCloud Policies via the JumpCloud PowerShell Module. + + New-JCPolicy + + Name + + The name of the policy to create + + System.String + + System.String + + + None + + + registryFile + + A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template. + + System.IO.FileInfo + + System.IO.FileInfo + + + None + + + Values + + The values object either built manually or passed in through Get-JCPolicy + + System.Object[] + + System.Object[] + + + None + + New-JCPolicy @@ -10025,6 +10064,57 @@ SystemID CommandID Status None + + New-JCPolicy + + Name + + The name of the policy to create + + System.String + + System.String + + + None + + + TemplateID + + The ID of the policy template to create as a new JumpCloud Policy + + System.String + + System.String + + + None + + + TemplateName + + The Name of the policy template to create as a new JumpCloud Policy + + System.String + + System.String + + + None + + + Values + + The values object either built manually or passed in through Get-JCPolicy + + System.Object[] + + System.Object[] + + + None + + New-JCPolicy @@ -10078,6 +10168,18 @@ SystemID CommandID Status None + + registryFile + + A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template. + + System.IO.FileInfo + + System.IO.FileInfo + + + None + TemplateID @@ -10090,7 +10192,7 @@ SystemID CommandID Status None - + TemplateName The Name of the policy template to create as a new JumpCloud Policy @@ -14908,6 +15010,45 @@ Enter a value between 1 and 2: None + + Set-JCPolicy + + NewName + + The new name to set on the existing JumpCloud Policy + + System.String + + System.String + + + None + + + registryFile + + A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template. + + System.IO.FileInfo + + System.IO.FileInfo + + + None + + + Values + + The values object either built manually or passed in through Get-JCPolicy + + System.Object[] + + System.Object[] + + + None + + @@ -14946,6 +15087,18 @@ Enter a value between 1 and 2: None + + registryFile + + A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template. + + System.IO.FileInfo + + System.IO.FileInfo + + + None + Values diff --git a/PowerShell/ModuleChangelog.md b/PowerShell/ModuleChangelog.md index cd6a1d660..5c7030569 100644 --- a/PowerShell/ModuleChangelog.md +++ b/PowerShell/ModuleChangelog.md @@ -1,3 +1,25 @@ +## 2.6.1 + +Release Date: June 22, 2023 + +#### RELEASE NOTES + +``` +{{Fill in the Release Notes}} +``` + +#### FEATURES: + +{{Fill in the Features}} + +#### IMPROVEMENTS: + +{{Fill in the Improvements}} + +#### BUG FIXES: + +{{Fill in the Bug Fixes}} + ## 2.5.1 Release Date: May 30, 2023 From a58da1ed1188c0e80596ec02ec0cafd6cd620978 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Thu, 22 Jun 2023 11:55:36 -0600 Subject: [PATCH 09/77] changelog --- PowerShell/ModuleChangelog.md | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/PowerShell/ModuleChangelog.md b/PowerShell/ModuleChangelog.md index 5c7030569..b39423c23 100644 --- a/PowerShell/ModuleChangelog.md +++ b/PowerShell/ModuleChangelog.md @@ -5,20 +5,12 @@ Release Date: June 22, 2023 #### RELEASE NOTES ``` -{{Fill in the Release Notes}} +This release introduces a new parameter, registryFile, to New-JCPolicy and Set-JCPolicy ``` #### FEATURES: -{{Fill in the Features}} - -#### IMPROVEMENTS: - -{{Fill in the Improvements}} - -#### BUG FIXES: - -{{Fill in the Bug Fixes}} +Admins can now upload a .reg file to a new or existing Windows - Advanced: Custom Registry Keys Policy ## 2.5.1 From 1b2bafc614058022e5b90932e47333eac0c0288a Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Thu, 22 Jun 2023 11:55:46 -0600 Subject: [PATCH 10/77] fix file path --- .../Tests/Private/Policies/Convert-RegToPSObject.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/JumpCloud Module/Tests/Private/Policies/Convert-RegToPSObject.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/Policies/Convert-RegToPSObject.Tests.ps1 index 721589962..28253e3d7 100644 --- a/PowerShell/JumpCloud Module/Tests/Private/Policies/Convert-RegToPSObject.Tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Private/Policies/Convert-RegToPSObject.Tests.ps1 @@ -1,5 +1,5 @@ BeforeAll { - $PesterRegistryFilePath = "$PSScriptRoot/Private/Policies/Reg_File/PesterRegFile.reg" + $PesterRegistryFilePath = "$PSScriptRoot/Reg_File/PesterRegFile.reg" } Describe -Tag:('JCPolicy') 'Registry File Tests' { From 3c2182d33889c977cb8424d1cf272d32b2c05936 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Thu, 22 Jun 2023 12:42:13 -0600 Subject: [PATCH 11/77] fiix registry file tests --- PowerShell/JumpCloud Module/Tests/DefineEnvironment.ps1 | 2 ++ .../Tests/Private/Policies/Convert-RegToPSObject.Tests.ps1 | 6 +----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/PowerShell/JumpCloud Module/Tests/DefineEnvironment.ps1 b/PowerShell/JumpCloud Module/Tests/DefineEnvironment.ps1 index 8b35e4445..7304a85d2 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 index 28253e3d7..87ac488d9 100644 --- a/PowerShell/JumpCloud Module/Tests/Private/Policies/Convert-RegToPSObject.Tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Private/Policies/Convert-RegToPSObject.Tests.ps1 @@ -1,10 +1,6 @@ -BeforeAll { - $PesterRegistryFilePath = "$PSScriptRoot/Reg_File/PesterRegFile.reg" -} Describe -Tag:('JCPolicy') 'Registry File Tests' { - Context 'Test Reg File Conversion' { - $regFile = Convert-RegToPSObject -regFilePath $PesterRegistryFilePath + $regFile = Convert-RegToPSObject -regFilePath $PesterParams_RegistryFilePath It 'Convert-RegToPSObject should return object with values' { foreach ($regKey in $regFile) { $regKey.customLocation | Should -Not -BeNullOrEmpty From da6cd41baacd3cdccaca48c3bf088cc516fdadc7 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Thu, 22 Jun 2023 12:49:25 -0600 Subject: [PATCH 12/77] dynamicparam standard paramset --- PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 b/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 index d80b0cb04..915a7685a 100644 --- a/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 +++ b/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 @@ -102,6 +102,7 @@ function New-JCPolicy { } else { $ParameterAttribute.HelpMessage = "$($key.help)" } + $ParameterAttribute.ParameterSetName = "Standard" # Add the attributes to the attributes collection $AttributeCollection.Add($ParameterAttribute) # Add the param From d1da9c561f3f566cc41110586a3ad5adeb0dbac1 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Thu, 22 Jun 2023 19:33:35 +0000 Subject: [PATCH 13/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/JumpCloud Module/JumpCloud.nuspec b/PowerShell/JumpCloud Module/JumpCloud.nuspec index 0d0621c11..c42bc2607 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.6.0.8602-202305261756 + 2.6.1.8896-202306221931 PowerShell functions to manage a JumpCloud Directory-as-a-Service JumpCloud Solutions Architect Team JumpCloud From ebc2a2be0a48ad13f16bdb21b1102d1f36f3344e Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Thu, 22 Jun 2023 14:12:46 -0600 Subject: [PATCH 14/77] remove $ from hash --- PowerShell/JumpCloud Module/Tests/DefineEnvironment.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/JumpCloud Module/Tests/DefineEnvironment.ps1 b/PowerShell/JumpCloud Module/Tests/DefineEnvironment.ps1 index 7304a85d2..dabe3fae5 100644 --- a/PowerShell/JumpCloud Module/Tests/DefineEnvironment.ps1 +++ b/PowerShell/JumpCloud Module/Tests/DefineEnvironment.ps1 @@ -80,7 +80,7 @@ $PesterParamsHash_Common = @{ ImportPath = "$PSScriptRoot/Csv_Files/import" UpdatePath = "$PSScriptRoot/Csv_Files/update" # Registry Files - $RegistryFilePath = "$PSScriptRoot/Reg_File/PesterRegFile.reg" + RegistryFilePath = "$PSScriptRoot/Reg_File/PesterRegFile.reg" # Policy Info MultiplePolicyList = @('1 Linux', 'Disable USB Storage - Linux') SinglePolicyList = @('Disable USB Storage - Linux') From 3bd98133ce3c6ebf90a5e9e2b8214cef655390a7 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Thu, 22 Jun 2023 20:19:39 +0000 Subject: [PATCH 15/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/JumpCloud Module/JumpCloud.nuspec b/PowerShell/JumpCloud Module/JumpCloud.nuspec index c42bc2607..91123267d 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.6.1.8896-202306221931 + 2.6.1.8907-202306222017 PowerShell functions to manage a JumpCloud Directory-as-a-Service JumpCloud Solutions Architect Team JumpCloud From a888b6d97d353fa97be70a5c536db4af92d01d7c Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Thu, 22 Jun 2023 15:13:15 -0600 Subject: [PATCH 16/77] use pester environ variable for reg file --- .../Tests/Public/Policies/New-JCPolicy.tests.ps1 | 3 +-- .../Tests/Public/Policies/Set-JCPolicy.tests.ps1 | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) 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 4b1e214c8..d3db8d1b1 100644 --- a/PowerShell/JumpCloud Module/Tests/Public/Policies/New-JCPolicy.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Policies/New-JCPolicy.tests.ps1 @@ -291,8 +291,7 @@ Describe -Tag:('JCPolicy') 'New-JCPolicy' { } Context 'Create new policy using Registry file' { It 'New-JCPolicy using regFilePath parameter' { - $PesterRegistryFilePath = "$PSScriptRoot/Reg_File/PesterRegFile.reg" - $registryPolicy = New-JCPolicy -Name 'Pester - RegFileUpload' -registryFile $PesterRegistryFilePath + $registryPolicy = New-JCPolicy -Name 'Pester - RegFileUpload' -registryFile $PesterParams_RegistryFilePath $registryPolicy.name | Should -Not -BeNullOrEmpty $registryPolicy.templateID | Should -Be '5f07273cb544065386e1ce6f' $registryPolicy.values | Should -Not -BeNullOrEmpty 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 df6176e62..c7d5dd664 100644 --- a/PowerShell/JumpCloud Module/Tests/Public/Policies/Set-JCPolicy.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Policies/Set-JCPolicy.tests.ps1 @@ -454,12 +454,11 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' { } Context 'Update registry policy using Registry file' { It 'Set-JCPolicy using regFilePath parameter' { - $PesterRegistryFilePath = "$PSScriptRoot/Reg_File/PesterRegFile.reg" - $registryPolicy = New-JCPolicy -Name "Pester - RegFileUpload $(new-randomString -NumberOfChars 8)" -registryFile $PesterRegistryFilePath + $registryPolicy = New-JCPolicy -Name "Pester - RegFileUpload $(new-randomString -NumberOfChars 8)" -registryFile $PesterParams_RegistryFilePath $NewName = "Pester - RegFileUpload $(new-randomString -NumberOfChars 8)" - $registryPolicyUpdated = Set-JCPolicy -PolicyID $registryPolicy.Id -NewName $NewName -registryFile $PesterRegistryFilePath + $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 From c9a955b75d0e358967bb07691c804fa0690e08d7 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Thu, 22 Jun 2023 21:19:37 +0000 Subject: [PATCH 17/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md | 2 +- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 91123267d..4172e4fe4 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.6.1.8907-202306222017 + 2.6.1.8919-202306222117 PowerShell functions to manage a JumpCloud Directory-as-a-Service JumpCloud Solutions Architect Team JumpCloud From 8c479b052cabf3e0a7e5bca27a88ce4e28ee51a6 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Mon, 26 Jun 2023 11:36:10 -0600 Subject: [PATCH 18/77] remove registryfile paramset and add trycatch --- .../Public/Policies/Set-JCPolicy.ps1 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 index 7b3e48f99..8d2a99448 100644 --- a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 +++ b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 @@ -24,7 +24,6 @@ function Set-JCPolicy { [System.object[]] $Values, [Parameter(Mandatory = $false, - ParameterSetName = 'RegistryFile', HelpMessage = 'A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template.')] [System.IO.FileInfo]$registryFile ) @@ -220,7 +219,11 @@ function Set-JCPolicy { } $updatedPolicyObject = $newObject | Select-Object configFieldID, configFieldName, value if ($registryFile) { - $regKeys = Convert-RegToPSObject -regFilePath $registryFile + try { + $regKeys = Convert-RegToPSObject -regFilePath $registryFile + } catch { + throw $_ + } $updatedPolicyObject.value += $regKeys Write-Debug $updatedPolicyObject } @@ -241,7 +244,11 @@ function Set-JCPolicy { if (($templateObject.objectMap).count -gt 0) { if ($registryFile) { $updatedPolicyObject = $foundPolicy.values - $regKeys = Convert-RegToPSObject -regFilePath $registryFile + try { + $regKeys = Convert-RegToPSObject -regFilePath $registryFile + } catch { + throw $_ + } $updatedPolicyObject.value += $regKeys Write-Debug $updatedPolicyObject } else { From 8f500a4e1fc394b91ed43d1b83d72533abac6383 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Mon, 26 Jun 2023 17:45:25 +0000 Subject: [PATCH 19/77] Updating PowerShell Module;[skip ci] --- .../JumpCloud Module/Docs/Set-JCPolicy.md | 13 +++---- .../Docs/Set-JCSettingsFile.md | 2 +- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- PowerShell/JumpCloud Module/JumpCloud.psd1 | 2 +- .../JumpCloud Module/en-Us/JumpCloud-help.xml | 39 ++++++------------- 5 files changed, 20 insertions(+), 38 deletions(-) diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md b/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md index 156ac90f7..8770dbc8f 100644 --- a/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md +++ b/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md @@ -19,17 +19,14 @@ Set-JCPolicy can display the available parameters per policy if a `PolicyName` o ### ByID (Default) ``` -Set-JCPolicy -PolicyID [-NewName ] [-Values ] [] +Set-JCPolicy -PolicyID [-NewName ] [-Values ] [-registryFile ] + [] ``` ### ByName ``` -Set-JCPolicy -PolicyName [-NewName ] [-Values ] [] -``` - -### RegistryFile -``` -Set-JCPolicy [-NewName ] [-Values ] [-registryFile ] [] +Set-JCPolicy -PolicyName [-NewName ] [-Values ] [-registryFile ] + [] ``` ## DESCRIPTION @@ -132,7 +129,7 @@ A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" ```yaml Type: System.IO.FileInfo -Parameter Sets: RegistryFile +Parameter Sets: (All) Aliases: Required: False diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md b/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md index ba6b37a0c..f8bf10130 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 [-moduleBannerMessageCount ] [-parallelOverride ] [] +Set-JCSettingsFile [-parallelOverride ] [-moduleBannerMessageCount ] [] ``` ## DESCRIPTION diff --git a/PowerShell/JumpCloud Module/JumpCloud.nuspec b/PowerShell/JumpCloud Module/JumpCloud.nuspec index 4172e4fe4..7143f6470 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.6.1.8919-202306222117 + 2.6.1.8939-202306261743 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 309882f0b..0b613e2d8 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/22/2023 +# Generated on: 6/26/2023 # @{ diff --git a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml index db3ce8f66..d858938c7 100644 --- a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml +++ b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml @@ -14958,6 +14958,18 @@ Enter a value between 1 and 2: None + + registryFile + + A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template. + + System.IO.FileInfo + + System.IO.FileInfo + + + None + Values @@ -14997,33 +15009,6 @@ Enter a value between 1 and 2: None - - Values - - The values object either built manually or passed in through Get-JCPolicy - - System.Object[] - - System.Object[] - - - None - - - - Set-JCPolicy - - NewName - - The new name to set on the existing JumpCloud Policy - - System.String - - System.String - - - None - registryFile From bb06610f93be98a929cd63870aec921407c5b528 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Mon, 26 Jun 2023 18:07:02 +0000 Subject: [PATCH 20/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 767d9daf35b1012ab63dc0606edf5ded5f3034aa Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Mon, 26 Jun 2023 14:22:18 -0600 Subject: [PATCH 21/77] Update workflows.yml --- .circleci/workflows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/workflows.yml b/.circleci/workflows.yml index 17d4c4a3a..88ef47756 100755 --- a/.circleci/workflows.yml +++ b/.circleci/workflows.yml @@ -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 From 349c0b20884347be8f1b72f5193de765b41fdbe3 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Mon, 26 Jun 2023 20:28:34 +0000 Subject: [PATCH 22/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md | 2 +- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md b/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md index ba6b37a0c..f8bf10130 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 [-moduleBannerMessageCount ] [-parallelOverride ] [] +Set-JCSettingsFile [-parallelOverride ] [-moduleBannerMessageCount ] [] ``` ## DESCRIPTION diff --git a/PowerShell/JumpCloud Module/JumpCloud.nuspec b/PowerShell/JumpCloud Module/JumpCloud.nuspec index 7143f6470..ad1571372 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.6.1.8939-202306261743 + 2.6.1.8981-202306262026 PowerShell functions to manage a JumpCloud Directory-as-a-Service JumpCloud Solutions Architect Team JumpCloud From b75ee051f53a2cf89cbccc458d06e5fe62cfd0a6 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Wed, 28 Jun 2023 10:26:05 -0600 Subject: [PATCH 23/77] SA-3406 Bug Fix --- .../Private/NestedFunctions/Get-JCResults.ps1 | 13 +++++-------- PowerShell/ModuleChangelog.md | 4 ++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 index 0a20f1c58..27116b2c8 100644 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 @@ -170,8 +170,8 @@ Function Get-JCResults { else { if ($totalCountHeader) { # Add results to results list - $content = $response.Content - [void]$resultsArray.Add($content) + $content = $response.Content | ConvertFrom-Json + [void]$resultsArray.AddRange($content) } else { # Add results to results list $content = $response.Content | ConvertFrom-Json @@ -220,9 +220,9 @@ 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 + [void]$resultsArray.AddRange($content) + Write-Debug ("Page: $($i+1) Amount: " + ($content).Count) } else { # Add results to results list $content = $response.Content | ConvertFrom-Json @@ -238,9 +238,6 @@ Function Get-JCResults { } } end { - if ($totalCountHeader) { - $resultsArray = $resultsArray | ConvertFrom-Json - } # Return complete results return $resultsArray } diff --git a/PowerShell/ModuleChangelog.md b/PowerShell/ModuleChangelog.md index b39423c23..e05641db5 100644 --- a/PowerShell/ModuleChangelog.md +++ b/PowerShell/ModuleChangelog.md @@ -12,6 +12,10 @@ This release introduces a new parameter, registryFile, to New-JCPolicy and Set-J 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 From 72d7ba004e5ed1693ac3b08db288ee5cc85c563b Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Wed, 28 Jun 2023 16:34:07 +0000 Subject: [PATCH 24/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/JumpCloud.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/JumpCloud Module/JumpCloud.psd1 b/PowerShell/JumpCloud Module/JumpCloud.psd1 index 0b613e2d8..869a837ba 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/26/2023 +# Generated on: 6/28/2023 # @{ From e50ac363b7fa69298c2ea08260c8c4debe7cbde1 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Fri, 30 Jun 2023 12:15:21 -0600 Subject: [PATCH 25/77] Update workflows.yml --- .circleci/workflows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/workflows.yml b/.circleci/workflows.yml index 88ef47756..5d627a52c 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 From 08562e4cc883aeb09bdaabb3926615dc0bb99eb6 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Fri, 30 Jun 2023 12:15:36 -0600 Subject: [PATCH 26/77] int dword conversion --- .../JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 b/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 index b19e1727e..2536f921c 100644 --- a/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 +++ b/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 @@ -47,7 +47,7 @@ function Convert-RegToPSObject { if ($valueObject[1].StartsWith("dword:")) { #DWORD $customRegType = "DWORD" - $customData = ($valueObject[1]).Substring(5) + $customData = [int]"0x$(($valueObject[1]).Substring(6))" } elseif ($valueObject[1].StartsWith("hex(b):")) { #QWORD $customRegType = "QWORD" From 79f46964ebbd188935c5f9e86d9e9cc8c58155ab Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Fri, 30 Jun 2023 12:15:58 -0600 Subject: [PATCH 27/77] remove standard paramset --- .../Public/Policies/New-JCPolicy.ps1 | 188 +++++++++--------- 1 file changed, 92 insertions(+), 96 deletions(-) diff --git a/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 b/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 index 915a7685a..cca21e715 100644 --- a/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 +++ b/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 @@ -5,24 +5,19 @@ function New-JCPolicy { ParameterSetName = 'ByID', ValueFromPipelineByPropertyName = $true, HelpMessage = 'The ID of the policy template to create as a new JumpCloud Policy')] - [Parameter(ParameterSetName = 'Standard')] [System.String] $TemplateID, [Parameter(Mandatory = $true, ParameterSetName = 'ByName', HelpMessage = 'The Name of the policy template to create as a new JumpCloud Policy')] - [Parameter(ParameterSetName = 'Standard')] [System.String] $TemplateName, [Parameter(Mandatory = $false, HelpMessage = 'The name of the policy to create. If left unspecified, the cmdlet will attempt to create the policy with the default name defined by the selected policy template.')] - [Parameter(ParameterSetName = 'Standard')] - [Parameter(ParameterSetName = 'RegistryFile')] [System.String] $Name, [Parameter(ValueFromPipelineByPropertyName = $true, HelpMessage = 'The values object either built manually or passed in through Get-JCPolicy')] - [Parameter(ParameterSetName = 'Standard')] [System.object[]] $Values, [Parameter(Mandatory = $false, @@ -31,87 +26,84 @@ function New-JCPolicy { [System.IO.FileInfo]$registryFile ) DynamicParam { - if ($PSCmdlet.ParameterSetName -eq "Standard") { - if ($PSBoundParameters["TemplateID"]) { - $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute - $ParameterAttribute.Mandatory = $false - $ParameterAttribute.ParameterSetName = "ByID" - # Get the policy template by ID - $templateObject = Get-JCPolicyTemplateConfigField -templateID $templateID - if ([String]::IsNullOrEmpty($templateObject.defaultName)) { - throw "Could not find policy template by ID" - } + if ($PSBoundParameters["TemplateID"]) { + $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute + $ParameterAttribute.Mandatory = $false + $ParameterAttribute.ParameterSetName = "ByID" + # Get the policy template by ID + $templateObject = Get-JCPolicyTemplateConfigField -templateID $templateID + if ([String]::IsNullOrEmpty($templateObject.defaultName)) { + throw "Could not find policy template by ID" + } - } elseif ($PSBoundParameters["TemplateName"]) { - $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute - $ParameterAttribute.Mandatory = $false - $ParameterAttribute.ParameterSetName = "ByName" - # Get the policy by Name - if ($TemplateName -in $global:TemplateNameList.Name) { - $matchedTemplate = $templateNameList[$templateNameList.Name.IndexOf($TemplateName)].id - } else { - throw "template list missing; have you run Connect-JCOnline" - } - $templateObject = Get-JCPolicyTemplateConfigField -templateID $matchedTemplate - if ([String]::IsNullOrEmpty($templateObject.defaultName)) { - throw "Could not find policy template by specified Name" - } + } elseif ($PSBoundParameters["TemplateName"]) { + $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute + $ParameterAttribute.Mandatory = $false + $ParameterAttribute.ParameterSetName = "ByName" + # Get the policy by Name + if ($TemplateName -in $global:TemplateNameList.Name) { + $matchedTemplate = $templateNameList[$templateNameList.Name.IndexOf($TemplateName)].id + } else { + throw "template list missing; have you run Connect-JCOnline" } + $templateObject = Get-JCPolicyTemplateConfigField -templateID $matchedTemplate + if ([String]::IsNullOrEmpty($templateObject.defaultName)) { + throw "Could not find policy template by specified Name" + } + } - if ($templateObject.objectMap -And ($PSBoundParameters["TemplateName"] -OR $PSBoundParameters["TemplateID"])) { - $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary - # Foreach key in the supplied config file: - foreach ($key in $templateObject.objectMap) { - # Set the dynamic parameters' name - $ParamName_Filter = "$($key.configFieldName)" - # Create the collection of attributes - $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] - # If ValidateSet is specified in the config file, set the value here: - # If the type of value is a bool, create a custom validateSet attribute here: - $paramType = $($key.type) - switch ($paramType) { - 'boolean' { - $arrSet = @("true", "false") - $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) - $AttributeCollection.Add($ValidateSetAttribute) - } - 'multi' { - $paramType = 'string' - $arrSet = $key.validation.values - $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) - $AttributeCollection.Add($ValidateSetAttribute) - } - 'file' { - $paramType = 'string' - } - 'listbox' { - $paramType = [system.string[]] - } - 'table' { - $paramType = [system.object[]] - } - 'exclude' { - Continue - } - Default { - $paramType = 'string' - } + if ($templateObject.objectMap -And ($PSBoundParameters["TemplateName"] -OR $PSBoundParameters["TemplateID"])) { + $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary + # Foreach key in the supplied config file: + foreach ($key in $templateObject.objectMap) { + # Set the dynamic parameters' name + $ParamName_Filter = "$($key.configFieldName)" + # Create the collection of attributes + $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] + # If ValidateSet is specified in the config file, set the value here: + # If the type of value is a bool, create a custom validateSet attribute here: + $paramType = $($key.type) + switch ($paramType) { + 'boolean' { + $arrSet = @("true", "false") + $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) + $AttributeCollection.Add($ValidateSetAttribute) } - if ([String]::isNullorEmpty($($key.help))) { - $ParameterAttribute.HelpMessage = "sets the value for the $($key.name) field" - } else { - $ParameterAttribute.HelpMessage = "$($key.help)" + 'multi' { + $paramType = 'string' + $arrSet = $key.validation.values + $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) + $AttributeCollection.Add($ValidateSetAttribute) + } + 'file' { + $paramType = 'string' + } + 'listbox' { + $paramType = [system.string[]] + } + 'table' { + $paramType = [system.object[]] + } + 'exclude' { + Continue } - $ParameterAttribute.ParameterSetName = "Standard" - # Add the attributes to the attributes collection - $AttributeCollection.Add($ParameterAttribute) - # Add the param - $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParamName_Filter, $paramType, $AttributeCollection) - $RuntimeParameterDictionary.Add($ParamName_Filter, $RuntimeParameter) + Default { + $paramType = 'string' + } + } + if ([String]::isNullorEmpty($($key.help))) { + $ParameterAttribute.HelpMessage = "sets the value for the $($key.name) field" + } else { + $ParameterAttribute.HelpMessage = "$($key.help)" } - # Returns the dictionary - return $RuntimeParameterDictionary + # Add the attributes to the attributes collection + $AttributeCollection.Add($ParameterAttribute) + # Add the param + $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParamName_Filter, $paramType, $AttributeCollection) + $RuntimeParameterDictionary.Add($ParamName_Filter, $RuntimeParameter) } + # Returns the dictionary + return $RuntimeParameterDictionary } } begin { @@ -121,7 +113,27 @@ function New-JCPolicy { } } process { - if ($PSCmdlet.ParameterSetName -eq "Standard") { + if ($PSCmdlet.ParameterSetName -eq 'RegistryFile') { + try { + $regKeys = Convert-RegToPSObject -regFilePath $registryFile + } catch { + throw $_ + } + $body = @{ + "name" = if (!$Name) { "Advanced: Custom Registry Keys" } else { $($Name) } + "values" = @(@{ + "configFieldID" = '5f07273cb544065386e1ce70' + "configFieldName" = 'customRegTable' + "sensitive" = $($false) + "value" = @($regKeys) + }) + "template" = @{ + "id" = "5f07273cb544065386e1ce6f" + } + } + $body = ConvertTo-Json -InputObject $body -Depth 10 + Write-Debug $Body + } else { $params = $PSBoundParameters $paramterSet = $params.keys $DynamicParamSet = $false @@ -271,22 +283,6 @@ function New-JCPolicy { } | ConvertTo-Json -Depth 99 } - } elseif ($PSCmdlet.ParameterSetName -eq 'RegistryFile') { - $regKeys = Convert-RegToPSObject -regFilePath $registryFile - $body = @{ - "name" = if (!$Name) { "Advanced: Custom Registry Keys" } else { $($Name) } - "values" = @(@{ - "configFieldID" = '5f07273cb544065386e1ce70' - "configFieldName" = 'customRegTable' - "sensitive" = $($false) - "value" = @($regKeys) - }) - "template" = @{ - "id" = "5f07273cb544065386e1ce6f" - } - } - $body = ConvertTo-Json -InputObject $body -Depth 10 - Write-Debug $Body } $headers = @{ 'x-api-key' = $env:JCApiKey From 78b87531d9b3c72421afd0838a861553535a1407 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Fri, 30 Jun 2023 12:16:14 -0600 Subject: [PATCH 28/77] new test to validate regfile values --- .../Policies/Convert-RegToPSObject.Tests.ps1 | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/PowerShell/JumpCloud Module/Tests/Private/Policies/Convert-RegToPSObject.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/Policies/Convert-RegToPSObject.Tests.ps1 index 87ac488d9..ef1a715df 100644 --- a/PowerShell/JumpCloud Module/Tests/Private/Policies/Convert-RegToPSObject.Tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Private/Policies/Convert-RegToPSObject.Tests.ps1 @@ -9,5 +9,32 @@ Describe -Tag:('JCPolicy') 'Registry File Tests' { $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 From b4c931610b80c7fa68e94f6299e64c51de1ce0c3 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Fri, 30 Jun 2023 12:16:19 -0600 Subject: [PATCH 29/77] Update PesterRegFile.reg --- .../Tests/Reg_File/PesterRegFile.reg | Bin 768 -> 826 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/PowerShell/JumpCloud Module/Tests/Reg_File/PesterRegFile.reg b/PowerShell/JumpCloud Module/Tests/Reg_File/PesterRegFile.reg index 4a7bca14437aa6a3f20632363a524875c01331be..e327cd0d37285a435168089b0030b8684d844db7 100644 GIT binary patch delta 43 mcmZo*+r>8F0i(;rhvL#H4CM^@3`Gnn3|0&VsBq&=btV7=ED9|E delta 19 bcmdnR*1$I50b}6AhvJhbFmf!mVq^jUOMV8P From 294acbedd227b61dc92e4cbb6f06caed6b05e5ac Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Fri, 30 Jun 2023 12:16:23 -0600 Subject: [PATCH 30/77] Update ModuleChangelog.md --- PowerShell/ModuleChangelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/ModuleChangelog.md b/PowerShell/ModuleChangelog.md index e05641db5..73e2081de 100644 --- a/PowerShell/ModuleChangelog.md +++ b/PowerShell/ModuleChangelog.md @@ -1,4 +1,4 @@ -## 2.6.1 +## 2.7.0 Release Date: June 22, 2023 From fe3d2219b84879e4180400e09f7b4d701f79ee1b Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Fri, 30 Jun 2023 18:23:21 +0000 Subject: [PATCH 31/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/Docs/JumpCloud.md | 2 +- .../JumpCloud Module/Docs/New-JCPolicy.md | 44 +-------------- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- PowerShell/JumpCloud Module/JumpCloud.psd1 | 4 +- .../JumpCloud Module/en-Us/JumpCloud-help.xml | 53 +------------------ 5 files changed, 6 insertions(+), 99 deletions(-) diff --git a/PowerShell/JumpCloud Module/Docs/JumpCloud.md b/PowerShell/JumpCloud Module/Docs/JumpCloud.md index 935ba2a34..f7c43d5d8 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.1 +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 c867cfb97..d974477d3 100644 --- a/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md +++ b/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md @@ -22,12 +22,6 @@ At a minimum to display the dynamic set of parameters per template, the `Templat New-JCPolicy -TemplateID [-Name ] [-Values ] [] ``` -### Standard -``` -New-JCPolicy [-TemplateID ] [-TemplateName ] [-Name ] [-Values ] - [] -``` - ### ByName ``` New-JCPolicy -TemplateName [-Name ] [-Values ] [] @@ -132,34 +126,10 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` -```yaml -Type: System.String -Parameter Sets: Standard -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: True (ByPropertyName) -Accept wildcard characters: False -``` - ### -TemplateName The Name of the policy template to create as a new JumpCloud Policy -```yaml -Type: System.String -Parameter Sets: Standard -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ```yaml Type: System.String Parameter Sets: ByName @@ -178,19 +148,7 @@ The values object either built manually or passed in through Get-JCPolicy ```yaml Type: System.Object[] -Parameter Sets: ByID, ByName, RegistryFile -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: True (ByPropertyName) -Accept wildcard characters: False -``` - -```yaml -Type: System.Object[] -Parameter Sets: Standard +Parameter Sets: (All) Aliases: Required: False diff --git a/PowerShell/JumpCloud Module/JumpCloud.nuspec b/PowerShell/JumpCloud Module/JumpCloud.nuspec index ad1571372..c022303cc 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.6.1.8981-202306262026 + 2.7.0.9012-202306301821 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 869a837ba..676587126 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/28/2023 +# Generated on: 6/30/2023 # @{ @@ -12,7 +12,7 @@ RootModule = 'JumpCloud.psm1' # Version number of this module. -ModuleVersion = '2.6.1' +ModuleVersion = '2.7.0' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml index d858938c7..ef6fa90f2 100644 --- a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml +++ b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml @@ -10064,57 +10064,6 @@ SystemID CommandID Status None - - New-JCPolicy - - Name - - The name of the policy to create - - System.String - - System.String - - - None - - - TemplateID - - The ID of the policy template to create as a new JumpCloud Policy - - System.String - - System.String - - - None - - - TemplateName - - The Name of the policy template to create as a new JumpCloud Policy - - System.String - - System.String - - - None - - - Values - - The values object either built manually or passed in through Get-JCPolicy - - System.Object[] - - System.Object[] - - - None - - New-JCPolicy @@ -10192,7 +10141,7 @@ SystemID CommandID Status None - + TemplateName The Name of the policy template to create as a new JumpCloud Policy From 96167c0c66d9763cefb1bc84e521b005a0ffd743 Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Fri, 30 Jun 2023 12:57:14 -0600 Subject: [PATCH 32/77] changlog + trigger pipeline --- PowerShell/ModuleChangelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/ModuleChangelog.md b/PowerShell/ModuleChangelog.md index 73e2081de..11bfe7db7 100644 --- a/PowerShell/ModuleChangelog.md +++ b/PowerShell/ModuleChangelog.md @@ -1,6 +1,6 @@ ## 2.7.0 -Release Date: June 22, 2023 +Release Date: June 30, 2023 #### RELEASE NOTES From fbba2ad9ebeba1b4c2c2dd1ab8dd7d1c51619607 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Fri, 30 Jun 2023 19:06:15 +0000 Subject: [PATCH 33/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/JumpCloud Module/JumpCloud.nuspec b/PowerShell/JumpCloud Module/JumpCloud.nuspec index c022303cc..314d295fd 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.7.0.9012-202306301821 + 2.7.0.9029-202306301903 PowerShell functions to manage a JumpCloud Directory-as-a-Service JumpCloud Solutions Architect Team JumpCloud From 6d7875bf263f5dd59771ce6db24454277a6340fe Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Fri, 30 Jun 2023 14:03:07 -0600 Subject: [PATCH 34/77] revert change for Get-JCResults --- .../Private/NestedFunctions/Get-JCResults.ps1 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 index 27116b2c8..47f05a862 100644 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 @@ -170,11 +170,11 @@ Function Get-JCResults { else { if ($totalCountHeader) { # Add results to results list - $content = $response.Content | ConvertFrom-Json + $content = $response.Content [void]$resultsArray.AddRange($content) } else { # Add results to results list - $content = $response.Content | ConvertFrom-Json + $content = $response.Content if ($null -eq $content.results) { [void]$resultsArray.Add($content) } else { @@ -238,6 +238,9 @@ Function Get-JCResults { } } end { + if ($totalCountHeader) { + $resultsArray = $resultsArray | ConvertFrom-Json + } # Return complete results return $resultsArray } From 4a77039c55e4fd614159b795b0925008e39b8b6d Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Mon, 3 Jul 2023 09:52:13 -0600 Subject: [PATCH 35/77] Revert "revert change for Get-JCResults" This reverts commit 6d7875bf263f5dd59771ce6db24454277a6340fe. --- .../Private/NestedFunctions/Get-JCResults.ps1 | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 index 47f05a862..27116b2c8 100644 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 @@ -170,11 +170,11 @@ Function Get-JCResults { else { if ($totalCountHeader) { # Add results to results list - $content = $response.Content + $content = $response.Content | ConvertFrom-Json [void]$resultsArray.AddRange($content) } else { # Add results to results list - $content = $response.Content + $content = $response.Content | ConvertFrom-Json if ($null -eq $content.results) { [void]$resultsArray.Add($content) } else { @@ -238,9 +238,6 @@ Function Get-JCResults { } } end { - if ($totalCountHeader) { - $resultsArray = $resultsArray | ConvertFrom-Json - } # Return complete results return $resultsArray } From 9bceaccd26bd54efb0805cdd03c0dbe2254d6da4 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Mon, 3 Jul 2023 17:14:40 +0000 Subject: [PATCH 36/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/JumpCloud.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/JumpCloud Module/JumpCloud.psd1 b/PowerShell/JumpCloud Module/JumpCloud.psd1 index 676587126..e11361fa9 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/30/2023 +# Generated on: 7/3/2023 # @{ From d1d0a05b563776d0dede3babb301947fee0ad725 Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Mon, 3 Jul 2023 11:21:40 -0600 Subject: [PATCH 37/77] fix for parallel get-jcresults --- .../JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 index 27116b2c8..80817d437 100644 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 @@ -238,6 +238,9 @@ Function Get-JCResults { } } end { + if ($parallel) { + $resultsArray = $resultsArray | ConvertFrom-Json + } # Return complete results return $resultsArray } From fb81ccca2e4739e44d4e3ff35b7625816d9cc4b6 Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Mon, 3 Jul 2023 11:26:10 -0600 Subject: [PATCH 38/77] parallel && totalCountHeader check --- .../JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 index 80817d437..fe9b66903 100644 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 @@ -238,7 +238,7 @@ Function Get-JCResults { } } end { - if ($parallel) { + if ($parallel -and $totalCountHeader) { $resultsArray = $resultsArray | ConvertFrom-Json } # Return complete results From 047dd942d5bbf0e80af0ec12abd6e80f04f20a75 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Mon, 3 Jul 2023 13:10:05 -0600 Subject: [PATCH 39/77] psobject array --- .../Private/NestedFunctions/Get-JCResults.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 index fe9b66903..aef88500b 100644 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 @@ -18,11 +18,11 @@ Function Get-JCResults { } if ($parallel) { - $resultsArray = [System.Collections.Concurrent.ConcurrentBag[object]]::new() + $resultsArray = [System.Collections.Concurrent.ConcurrentBag[psobject]]::new() $errorResults = [System.Collections.Concurrent.ConcurrentQueue[Exception]]::new() } else { Write-Debug "Running in Sequential" - $resultsArray = [System.Collections.Generic.List[object]]::new() + $resultsArray = [System.Collections.Generic.List[psobject]]::new() } $totalCount = 1 $limit = [int]$limit From 696498c68ce469c80bbb970f67da6800306d7151 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Mon, 3 Jul 2023 19:17:42 +0000 Subject: [PATCH 40/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/JumpCloud Module/JumpCloud.nuspec b/PowerShell/JumpCloud Module/JumpCloud.nuspec index 314d295fd..e2d7768c2 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.7.0.9029-202306301903 + 2.7.0.9083-202307031914 PowerShell functions to manage a JumpCloud Directory-as-a-Service JumpCloud Solutions Architect Team JumpCloud From 9663af9cee236a320147f0467a155bf2204533e8 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Mon, 3 Jul 2023 19:24:15 +0000 Subject: [PATCH 41/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 69c151e77e41c2edc0c16b5c731d77b0f44f7caf Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Mon, 3 Jul 2023 14:50:10 -0600 Subject: [PATCH 42/77] registry file as dynamicParam (work in progress) --- .../Public/Policies/New-JCPolicy.ps1 | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 b/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 index cca21e715..3df682630 100644 --- a/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 +++ b/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 @@ -19,11 +19,11 @@ function New-JCPolicy { [Parameter(ValueFromPipelineByPropertyName = $true, HelpMessage = 'The values object either built manually or passed in through Get-JCPolicy')] [System.object[]] - $Values, - [Parameter(Mandatory = $false, - ParameterSetName = 'RegistryFile', - HelpMessage = 'A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template.')] - [System.IO.FileInfo]$registryFile + $Values + # [Parameter(Mandatory = $false, + # ParameterSetName = 'RegistryFile', + # HelpMessage = 'A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template.')] + # [System.IO.FileInfo]$registryFile ) DynamicParam { if ($PSBoundParameters["TemplateID"]) { @@ -101,6 +101,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 @@ -120,7 +130,11 @@ function New-JCPolicy { throw $_ } $body = @{ - "name" = if (!$Name) { "Advanced: Custom Registry Keys" } else { $($Name) } + "name" = if (!$Name) { + "Advanced: Custom Registry Keys" + } else { + $($Name) + } "values" = @(@{ "configFieldID" = '5f07273cb544065386e1ce70' "configFieldName" = 'customRegTable' @@ -229,6 +243,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 From d5a35e04821768e5fcbbe80132a78dd2a7876a04 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Mon, 3 Jul 2023 20:57:27 +0000 Subject: [PATCH 43/77] Updating PowerShell Module;[skip ci] --- .../JumpCloud Module/Docs/New-JCPolicy.md | 20 -------- .../JumpCloud Module/en-Us/JumpCloud-help.xml | 51 ------------------- 2 files changed, 71 deletions(-) diff --git a/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md b/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md index d974477d3..0c5eb8b6f 100644 --- a/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md +++ b/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md @@ -27,11 +27,6 @@ New-JCPolicy -TemplateID [-Name ] [-Values ] [ [-Name ] [-Values ] [] ``` -### RegistryFile -``` -New-JCPolicy [-Name ] [-Values ] [-registryFile ] [] -``` - ## DESCRIPTION New-JCPolicy allows for the creation of new JumpCloud Policies via the JumpCloud PowerShell Module. @@ -95,21 +90,6 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -registryFile -A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template. - -```yaml -Type: System.IO.FileInfo -Parameter Sets: RegistryFile -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ### -TemplateID The ID of the policy template to create as a new JumpCloud Policy diff --git a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml index ef6fa90f2..ee7c6d2f3 100644 --- a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml +++ b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml @@ -9986,45 +9986,6 @@ SystemID CommandID Status New-JCPolicy allows for the creation of new JumpCloud Policies via the JumpCloud PowerShell Module. - - New-JCPolicy - - Name - - The name of the policy to create - - System.String - - System.String - - - None - - - registryFile - - A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template. - - System.IO.FileInfo - - System.IO.FileInfo - - - None - - - Values - - The values object either built manually or passed in through Get-JCPolicy - - System.Object[] - - System.Object[] - - - None - - New-JCPolicy @@ -10117,18 +10078,6 @@ SystemID CommandID Status None - - registryFile - - A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template. - - System.IO.FileInfo - - System.IO.FileInfo - - - None - TemplateID From df4201ce593985128dc2ee2a6f08725d86e4fb7f Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Wed, 5 Jul 2023 10:53:18 -0600 Subject: [PATCH 44/77] object array type --- .../Private/NestedFunctions/Get-JCResults.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 index aef88500b..5794a7c95 100644 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 @@ -18,11 +18,11 @@ Function Get-JCResults { } if ($parallel) { - $resultsArray = [System.Collections.Concurrent.ConcurrentBag[psobject]]::new() + $resultsArray = [System.Collections.Concurrent.ConcurrentBag[pscustomObject]]::new() $errorResults = [System.Collections.Concurrent.ConcurrentQueue[Exception]]::new() } else { Write-Debug "Running in Sequential" - $resultsArray = [System.Collections.Generic.List[psobject]]::new() + $resultsArray = [System.Collections.Generic.List[pscustomobject]]::new() } $totalCount = 1 $limit = [int]$limit From 4dc8c40fd694ae345371a7de7c13a358cf83971f Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Wed, 5 Jul 2023 17:01:07 +0000 Subject: [PATCH 45/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md | 2 +- PowerShell/JumpCloud Module/JumpCloud.psd1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md b/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md index ba6b37a0c..f8bf10130 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 [-moduleBannerMessageCount ] [-parallelOverride ] [] +Set-JCSettingsFile [-parallelOverride ] [-moduleBannerMessageCount ] [] ``` ## DESCRIPTION diff --git a/PowerShell/JumpCloud Module/JumpCloud.psd1 b/PowerShell/JumpCloud Module/JumpCloud.psd1 index e11361fa9..2ece838aa 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: 7/3/2023 +# Generated on: 7/5/2023 # @{ From 8820c025ca7b25ebfb341f0903d07eda296eb8d9 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Wed, 5 Jul 2023 12:05:09 -0600 Subject: [PATCH 46/77] Update Get-JCResults.ps1 --- .../JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 index 5794a7c95..f87283a7a 100644 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 @@ -174,7 +174,7 @@ Function Get-JCResults { [void]$resultsArray.AddRange($content) } else { # Add results to results list - $content = $response.Content | ConvertFrom-Json + $content = $response.Content if ($null -eq $content.results) { [void]$resultsArray.Add($content) } else { From b80b1c1a4cbd5973c0871430e973070f03920697 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Wed, 5 Jul 2023 18:12:49 +0000 Subject: [PATCH 47/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md | 2 +- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 e2d7768c2..86cc72dc0 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.7.0.9083-202307031914 + 2.7.0.9130-202307051810 PowerShell functions to manage a JumpCloud Directory-as-a-Service JumpCloud Solutions Architect Team JumpCloud From df09ffa802d2d3133bc93984b9ff60f8fe553a3b Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Wed, 5 Jul 2023 12:56:41 -0600 Subject: [PATCH 48/77] Update Get-JCResults.ps1 --- .../Private/NestedFunctions/Get-JCResults.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 index f87283a7a..fe9b66903 100644 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 @@ -18,11 +18,11 @@ Function Get-JCResults { } if ($parallel) { - $resultsArray = [System.Collections.Concurrent.ConcurrentBag[pscustomObject]]::new() + $resultsArray = [System.Collections.Concurrent.ConcurrentBag[object]]::new() $errorResults = [System.Collections.Concurrent.ConcurrentQueue[Exception]]::new() } else { Write-Debug "Running in Sequential" - $resultsArray = [System.Collections.Generic.List[pscustomobject]]::new() + $resultsArray = [System.Collections.Generic.List[object]]::new() } $totalCount = 1 $limit = [int]$limit @@ -174,7 +174,7 @@ Function Get-JCResults { [void]$resultsArray.AddRange($content) } else { # Add results to results list - $content = $response.Content + $content = $response.Content | ConvertFrom-Json if ($null -eq $content.results) { [void]$resultsArray.Add($content) } else { From d5c34bca23a1dfb497673d03e79aee1869cc0a88 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Wed, 5 Jul 2023 19:03:38 +0000 Subject: [PATCH 49/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/JumpCloud Module/JumpCloud.nuspec b/PowerShell/JumpCloud Module/JumpCloud.nuspec index 86cc72dc0..657035e73 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.7.0.9130-202307051810 + 2.7.0.9142-202307051901 PowerShell functions to manage a JumpCloud Directory-as-a-Service JumpCloud Solutions Architect Team JumpCloud From 59a3bd6f548e0824b5ea1c30782b1ccc4c19d730 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Wed, 5 Jul 2023 13:43:02 -0600 Subject: [PATCH 50/77] list to arraylist --- .../JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 index fe9b66903..cc108d705 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 From 24318e8fbc4153ce082d41d7797088b9598b2e0b Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Wed, 5 Jul 2023 19:51:05 +0000 Subject: [PATCH 51/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md | 2 +- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md b/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md index ba6b37a0c..f8bf10130 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 [-moduleBannerMessageCount ] [-parallelOverride ] [] +Set-JCSettingsFile [-parallelOverride ] [-moduleBannerMessageCount ] [] ``` ## DESCRIPTION diff --git a/PowerShell/JumpCloud Module/JumpCloud.nuspec b/PowerShell/JumpCloud Module/JumpCloud.nuspec index 657035e73..35ac7d726 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.7.0.9142-202307051901 + 2.7.0.9155-202307051948 PowerShell functions to manage a JumpCloud Directory-as-a-Service JumpCloud Solutions Architect Team JumpCloud From 33b9a1ebbaa51e27d9ccc47a82d6d2f09ba0bab3 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Wed, 5 Jul 2023 14:41:15 -0600 Subject: [PATCH 52/77] validate object size before adding to array --- .../Private/NestedFunctions/Get-JCResults.ps1 | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 index cc108d705..4e4822d35 100644 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 @@ -171,14 +171,22 @@ Function Get-JCResults { if ($totalCountHeader) { # Add results to results list $content = $response.Content | ConvertFrom-Json - [void]$resultsArray.AddRange($content) + if ($content.Count -eq 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 -eq 1) { + [void]$resultsArray.Add($content.results) + } else { + [void]$resultsArray.AddRange($content.results) + } } } @@ -221,17 +229,22 @@ Function Get-JCResults { if ($totalCountHeader) { # Add results to results list $content = $response.Content | ConvertFrom-Json - [void]$resultsArray.AddRange($content) - Write-Debug ("Page: $($i+1) Amount: " + ($content).Count) + if ($content.Count -eq 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 -eq 1) { + [void]$resultsArray.Add($content.results) + } else { + [void]$resultsArray.AddRange($content.results) + } } } } From 71d0590c06df26b8acb5744ff8cca909b426bb4a Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Wed, 5 Jul 2023 20:51:37 +0000 Subject: [PATCH 53/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/JumpCloud Module/JumpCloud.nuspec b/PowerShell/JumpCloud Module/JumpCloud.nuspec index 35ac7d726..d0138c701 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.7.0.9155-202307051948 + 2.7.0.9168-202307052049 PowerShell functions to manage a JumpCloud Directory-as-a-Service JumpCloud Solutions Architect Team JumpCloud From 15eea8d5e713c53e48a152988aa0217af1517fdb Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Wed, 5 Jul 2023 16:33:38 -0600 Subject: [PATCH 54/77] fix registry tests --- .../Tests/Public/Policies/New-JCPolicy.tests.ps1 | 2 +- .../Tests/Public/Policies/Set-JCPolicy.tests.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 d3db8d1b1..7686cf65f 100644 --- a/PowerShell/JumpCloud Module/Tests/Public/Policies/New-JCPolicy.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Policies/New-JCPolicy.tests.ps1 @@ -291,7 +291,7 @@ Describe -Tag:('JCPolicy') 'New-JCPolicy' { } Context 'Create new policy using Registry file' { It 'New-JCPolicy using regFilePath parameter' { - $registryPolicy = New-JCPolicy -Name 'Pester - RegFileUpload' -registryFile $PesterParams_RegistryFilePath + $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 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 c7d5dd664..8bdc1693c 100644 --- a/PowerShell/JumpCloud Module/Tests/Public/Policies/Set-JCPolicy.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Policies/Set-JCPolicy.tests.ps1 @@ -454,7 +454,7 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' { } Context 'Update registry policy using Registry file' { It 'Set-JCPolicy using regFilePath parameter' { - $registryPolicy = New-JCPolicy -Name "Pester - RegFileUpload $(new-randomString -NumberOfChars 8)" -registryFile $PesterParams_RegistryFilePath + $registryPolicy = New-JCPolicy -Name "Pester - RegFileUpload $(new-randomString -NumberOfChars 8)" -templateId '5f07273cb544065386e1ce6f' -registryFile $PesterParams_RegistryFilePath $NewName = "Pester - RegFileUpload $(new-randomString -NumberOfChars 8)" From 69311e7993b3e7b0558e366cf4b95d255af183d8 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Wed, 5 Jul 2023 22:40:13 +0000 Subject: [PATCH 55/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From fec5a0250102893b7f67055ea284537512fd71db Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Thu, 6 Jul 2023 10:28:45 -0600 Subject: [PATCH 56/77] Update Set-JCPolicy.tests.ps1 --- .../Tests/Public/Policies/Set-JCPolicy.tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8bdc1693c..8e3251b66 100644 --- a/PowerShell/JumpCloud Module/Tests/Public/Policies/Set-JCPolicy.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Policies/Set-JCPolicy.tests.ps1 @@ -462,7 +462,7 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' { $registryPolicyUpdated.name | Should -Be $NewName $registryPolicyUpdated.templateID | Should -Be '5f07273cb544065386e1ce6f' $registryPolicyUpdated.values | Should -Not -BeNullOrEmpty - $registryPolicyUpdated.values.value.count | Should -Be 8 + $registryPolicyUpdated.values.value.count | Should -Be 10 $registryPolicyUpdated.id | Should -Not -BeNullOrEmpty $registryPolicyUpdated.template | Should -Not -BeNullOrEmpty } From bc716d983b972d951988caf96097aa9b4a469b5b Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Thu, 6 Jul 2023 16:35:08 +0000 Subject: [PATCH 57/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- PowerShell/JumpCloud Module/JumpCloud.psd1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerShell/JumpCloud Module/JumpCloud.nuspec b/PowerShell/JumpCloud Module/JumpCloud.nuspec index d0138c701..5f4b8040b 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.7.0.9168-202307052049 + 2.7.0.9192-202307061633 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 2ece838aa..807daf05e 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: 7/5/2023 +# Generated on: 7/6/2023 # @{ From 9af7dc1de7c83404fe01d2550cc85ae954d517d1 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Wed, 12 Jul 2023 16:11:29 +0000 Subject: [PATCH 58/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/JumpCloud.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/JumpCloud Module/JumpCloud.psd1 b/PowerShell/JumpCloud Module/JumpCloud.psd1 index 807daf05e..6fe19f606 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: 7/6/2023 +# Generated on: 7/12/2023 # @{ From 6d66d52242458447638b749413f36e96464340cf Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Mon, 17 Jul 2023 10:24:06 -0600 Subject: [PATCH 59/77] adjust conditional --- .../Private/NestedFunctions/Get-JCResults.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 index 4e4822d35..2f9b21980 100644 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 @@ -171,7 +171,7 @@ Function Get-JCResults { if ($totalCountHeader) { # Add results to results list $content = $response.Content | ConvertFrom-Json - if ($content.Count -eq 1) { + if ($content.Count -le 1) { [void]$resultsArray.Add($content) } else { [void]$resultsArray.AddRange($content) @@ -182,7 +182,7 @@ Function Get-JCResults { if ($null -eq $content.results) { [void]$resultsArray.Add($content) } else { - if ($($content.results).Count -eq 1) { + if ($($content.results).Count -le 1) { [void]$resultsArray.Add($content.results) } else { [void]$resultsArray.AddRange($content.results) @@ -229,7 +229,7 @@ Function Get-JCResults { if ($totalCountHeader) { # Add results to results list $content = $response.Content | ConvertFrom-Json - if ($content.Count -eq 1) { + if ($content.Count -le 1) { [void]$resultsArray.Add($content) } else { [void]$resultsArray.AddRange($content) @@ -240,7 +240,7 @@ Function Get-JCResults { if ($null -eq $content.results) { [void]$resultsArray.Add($content) } else { - if ($($content.results).Count -eq 1) { + if ($($content.results).Count -le 1) { [void]$resultsArray.Add($content.results) } else { [void]$resultsArray.AddRange($content.results) From fa731318884389390037d2e36b49558d635c010b Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Mon, 17 Jul 2023 16:32:10 +0000 Subject: [PATCH 60/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md | 2 +- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- PowerShell/JumpCloud Module/JumpCloud.psd1 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md b/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md index ba6b37a0c..f8bf10130 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 [-moduleBannerMessageCount ] [-parallelOverride ] [] +Set-JCSettingsFile [-parallelOverride ] [-moduleBannerMessageCount ] [] ``` ## DESCRIPTION diff --git a/PowerShell/JumpCloud Module/JumpCloud.nuspec b/PowerShell/JumpCloud Module/JumpCloud.nuspec index 5f4b8040b..4b47f16bc 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.7.0.9192-202307061633 + 2.7.0.9224-202307171629 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 6fe19f606..23070e2e5 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: 7/12/2023 +# Generated on: 7/17/2023 # @{ From 2b511c2822d91fcdbf1e81096b0d68b300af51d3 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Tue, 18 Jul 2023 10:15:45 -0600 Subject: [PATCH 61/77] Update Get-JCResults.ps1 --- .../JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 index 2f9b21980..ee052bb3b 100644 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCResults.ps1 @@ -171,6 +171,7 @@ Function Get-JCResults { if ($totalCountHeader) { # Add results to results list $content = $response.Content | ConvertFrom-Json + # Check to see size of content if ($content.Count -le 1) { [void]$resultsArray.Add($content) } else { From 9d2a787b42d63ec7a4678221fa6214bb7f2fe9ae Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Tue, 18 Jul 2023 16:23:29 +0000 Subject: [PATCH 62/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md | 2 +- PowerShell/JumpCloud Module/JumpCloud.psd1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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.psd1 b/PowerShell/JumpCloud Module/JumpCloud.psd1 index 23070e2e5..3bdf6bb81 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: 7/17/2023 +# Generated on: 7/18/2023 # @{ From 8b5205fa8a3e1929e42446da0ecdc35fb79d3515 Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Wed, 19 Jul 2023 10:25:22 -0600 Subject: [PATCH 63/77] set policy dynamic param --- .../Public/Policies/Set-JCPolicy.ps1 | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 index 8d2a99448..1ecdd726d 100644 --- a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 +++ b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 @@ -22,10 +22,10 @@ function Set-JCPolicy { [Parameter(ValueFromPipelineByPropertyName = $true, HelpMessage = 'The values object either built manually or passed in through Get-JCPolicy')] [System.object[]] - $Values, - [Parameter(Mandatory = $false, - HelpMessage = 'A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template.')] - [System.IO.FileInfo]$registryFile + $Values + # [Parameter(Mandatory = $false, + # HelpMessage = 'A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template.')] + # [System.IO.FileInfo]$registryFile ) DynamicParam { @@ -102,6 +102,16 @@ 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) + } } # Returns the dictionary return $RuntimeParameterDictionary @@ -211,6 +221,15 @@ 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 + $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 = ($foundPolicy.values | Where-Object { $_.configFieldID -eq $templateObject.objectMap[$i].configFieldID }).value From 138001549d051c110850ce09d273114a1ee04f1d Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Wed, 19 Jul 2023 10:28:39 -0600 Subject: [PATCH 64/77] registry file cleanup --- .../Public/Policies/New-JCPolicy.ps1 | 301 ++++++++---------- .../Public/Policies/Set-JCPolicy.ps1 | 3 - 2 files changed, 136 insertions(+), 168 deletions(-) diff --git a/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 b/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 index 3df682630..0611c7751 100644 --- a/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 +++ b/PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1 @@ -20,10 +20,6 @@ function New-JCPolicy { HelpMessage = 'The values object either built manually or passed in through Get-JCPolicy')] [System.object[]] $Values - # [Parameter(Mandatory = $false, - # ParameterSetName = 'RegistryFile', - # HelpMessage = 'A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template.')] - # [System.IO.FileInfo]$registryFile ) DynamicParam { if ($PSBoundParameters["TemplateID"]) { @@ -123,190 +119,165 @@ function New-JCPolicy { } } process { - if ($PSCmdlet.ParameterSetName -eq 'RegistryFile') { - try { - $regKeys = Convert-RegToPSObject -regFilePath $registryFile - } catch { - throw $_ + $params = $PSBoundParameters + $paramterSet = $params.keys + $DynamicParamSet = $false + $requiredSet = @('TemplateID', 'TemplateName', 'Name' , 'Values') + foreach ($parameter in $paramterSet) { + $parameterComparison = Compare-Object -ReferenceObject $requiredSet -DifferenceObject $parameter + if ($parameterComparison | Where-Object { $_.sideindicator -eq "=>" }) { + $DynamicParamSet = $true + break } - $body = @{ - "name" = if (!$Name) { - "Advanced: Custom Registry Keys" - } else { - $($Name) - } - "values" = @(@{ - "configFieldID" = '5f07273cb544065386e1ce70' - "configFieldName" = 'customRegTable' - "sensitive" = $($false) - "value" = @($regKeys) - }) - "template" = @{ - "id" = "5f07273cb544065386e1ce6f" - } - } - $body = ConvertTo-Json -InputObject $body -Depth 10 - Write-Debug $Body - } else { - $params = $PSBoundParameters - $paramterSet = $params.keys - $DynamicParamSet = $false - $requiredSet = @('TemplateID', 'TemplateName', 'Name' , 'Values') - foreach ($parameter in $paramterSet) { - $parameterComparison = Compare-Object -ReferenceObject $requiredSet -DifferenceObject $parameter - if ($parameterComparison | Where-Object { $_.sideindicator -eq "=>" }) { - $DynamicParamSet = $true - break - } - } - # If TemplateName was specified get ID from hashed table - if ($PSBoundParameters["TemplateName"]) { - if ($TemplateName -in $templateNameList.Name) { - $TemplateID = $templateNameList[$templateNameList.Name.IndexOf($TemplateName)].id - } else { - throw "The template name: `"$templateName`" was not found in the list of available template names. To find the list of avaiable template names, type `"New-JCPolcy -TemplateName ` and press the tab key. If prompted, press `"y`" to view all availbale templates. Templates start with os type. To find the list of avaiable windows template names, type `"New-JCPolcy -TemplateName windows`" and press the tab key. To find the list of avaiable darwin template names, type `"New-JCPolcy -TemplateName darwin`" and press the tab key. To find the list of avaiable linux template names, type `"New-JCPolcy -TemplateName linux`" and press the tab key." - } - } - $templateObject = Get-JCPolicyTemplateConfigField -templateID $templateID - $policyName = if ($PSBoundParameters["name"]) { - $Name + } + # If TemplateName was specified get ID from hashed table + if ($PSBoundParameters["TemplateName"]) { + if ($TemplateName -in $templateNameList.Name) { + $TemplateID = $templateNameList[$templateNameList.Name.IndexOf($TemplateName)].id } else { - $templateObject.defaultName + throw "The template name: `"$templateName`" was not found in the list of available template names. To find the list of avaiable template names, type `"New-JCPolcy -TemplateName ` and press the tab key. If prompted, press `"y`" to view all availbale templates. Templates start with os type. To find the list of avaiable windows template names, type `"New-JCPolcy -TemplateName windows`" and press the tab key. To find the list of avaiable darwin template names, type `"New-JCPolcy -TemplateName darwin`" and press the tab key. To find the list of avaiable linux template names, type `"New-JCPolcy -TemplateName linux`" and press the tab key." } - if ($DynamicParamSet) { - $newObject = New-Object System.Collections.ArrayList - for ($i = 0; $i -lt $templateObject.objectMap.count; $i++) { - # If one of the dynamicParam config fields are passed in and is found in the policy template, set the new value: - if ($templateObject.objectMap[$i].configFieldName -in $params.keys) { - $keyName = $params.keys | Where-Object { $_ -eq $templateObject.objectMap[$i].configFieldName } - $keyValue = $params.$KeyName - # write-host "Setting value from $($keyName) $($KeyValue)" - switch ($templateObject.objectMap[$i].type) { - 'multi' { - $templateObject.objectMap[$i].value = $(($templateObject.objectMap[$i].validation | Where-Object { $_.Values -eq $keyValue }).keys) - $templateObject.objectMap[$i].value = $(($templateObject.objectMap[$i].validation | Where-Object { $_.Values -eq $keyValue }).keys) + } + $templateObject = Get-JCPolicyTemplateConfigField -templateID $templateID + $policyName = if ($PSBoundParameters["name"]) { + $Name + } else { + $templateObject.defaultName + } + if ($DynamicParamSet) { + $newObject = New-Object System.Collections.ArrayList + for ($i = 0; $i -lt $templateObject.objectMap.count; $i++) { + # If one of the dynamicParam config fields are passed in and is found in the policy template, set the new value: + if ($templateObject.objectMap[$i].configFieldName -in $params.keys) { + $keyName = $params.keys | Where-Object { $_ -eq $templateObject.objectMap[$i].configFieldName } + $keyValue = $params.$KeyName + # write-host "Setting value from $($keyName) $($KeyValue)" + switch ($templateObject.objectMap[$i].type) { + 'multi' { + $templateObject.objectMap[$i].value = $(($templateObject.objectMap[$i].validation | Where-Object { $_.Values -eq $keyValue }).keys) + $templateObject.objectMap[$i].value = $(($templateObject.objectMap[$i].validation | Where-Object { $_.Values -eq $keyValue }).keys) + } + 'file' { + $path = Test-Path -Path $keyValue + if ($path) { + # convert file path to base64 string + $templateObject.objectMap[$i].value = [convert]::ToBase64String((Get-Content -Path $keyValue -AsByteStream)) } - 'file' { - $path = Test-Path -Path $keyValue - if ($path) { - # convert file path to base64 string - $templateObject.objectMap[$i].value = [convert]::ToBase64String((Get-Content -Path $keyValue -AsByteStream)) + } + 'listbox' { + if ($($keyValue).getType().name -eq 'String') { + # Given case for single string passed in as dynamic input, convert to a list + $listRows = New-Object System.Collections.ArrayList + foreach ($regItem in $keyValue) { + $listRows.Add($regItem) | Out-Null } + $templateObject.objectMap[$i].value = $listRows + } elseif ($($keyValue).getType().name -eq 'Object[]') { + # else if the object passed in is a list already, pass in list + $templateObject.objectMap[$i].value = $($keyValue) } - 'listbox' { - if ($($keyValue).getType().name -eq 'String') { - # Given case for single string passed in as dynamic input, convert to a list - $listRows = New-Object System.Collections.ArrayList - foreach ($regItem in $keyValue) { - $listRows.Add($regItem) | Out-Null - } - $templateObject.objectMap[$i].value = $listRows - } elseif ($($keyValue).getType().name -eq 'Object[]') { - # else if the object passed in is a list already, pass in list - $templateObject.objectMap[$i].value = $($keyValue) + } + 'table' { + # For custom registry table, validate the object + if ($templateObject.objectMap[$i].configFieldName -eq "customRegTable") { + # get default value properties + $RegProperties = $templateObject.objectMap[$i].defaultValue | Get-Member -MemberType NoteProperty + # get passed in object properties + $ObjectProperties = if ($keyValue | Get-Member -MemberType NoteProperty) { + # for lists get note properties + ($keyValue | Get-Member -MemberType NoteProperty).Name + } else { + # for single objects, get keys + $keyValue.keys } - } - 'table' { - # For custom registry table, validate the object - if ($templateObject.objectMap[$i].configFieldName -eq "customRegTable") { - # get default value properties - $RegProperties = $templateObject.objectMap[$i].defaultValue | Get-Member -MemberType NoteProperty - # get passed in object properties - $ObjectProperties = if ($keyValue | Get-Member -MemberType NoteProperty) { - # for lists get note properties - ($keyValue | Get-Member -MemberType NoteProperty).Name - } else { - # for single objects, get keys - $keyValue.keys - } - $RegProperties | ForEach-Object { - if ($_.Name -notin $ObjectProperties) { - Throw "Custom Registry Tables require a `"$($_.Name)`" data string. The following data types were found: $($ObjectProperties)" - } - } - # reg type validation - $validRegTypes = @('DWORD', 'expandString', 'multiString', 'QWORD', 'String') - $($keyValue).customRegType | ForEach-Object { - if ($_ -notin $validRegTypes) { - throw "Custom Registry Tables require the `"customRegType`" data string to be one of: $validRegTypes, found: $_" - } + $RegProperties | ForEach-Object { + if ($_.Name -notin $ObjectProperties) { + Throw "Custom Registry Tables require a `"$($_.Name)`" data string. The following data types were found: $($ObjectProperties)" } } - $regRows = New-Object System.Collections.ArrayList - foreach ($regItem in $keyValue) { - $regRows.Add($regItem) | Out-Null + # reg type validation + $validRegTypes = @('DWORD', 'expandString', 'multiString', 'QWORD', 'String') + $($keyValue).customRegType | ForEach-Object { + if ($_ -notin $validRegTypes) { + throw "Custom Registry Tables require the `"customRegType`" data string to be one of: $validRegTypes, found: $_" + } } - $templateObject.objectMap[$i].value = $regRows } - Default { - $templateObject.objectMap[$i].value = $($keyValue) + $regRows = New-Object System.Collections.ArrayList + foreach ($regItem in $keyValue) { + $regRows.Add($regItem) | Out-Null } + $templateObject.objectMap[$i].value = $regRows } - $newObject.Add($templateObject.objectMap[$i]) | Out-Null - } elseif ('RegistryFile' -in $params.Keys) { - try { - $regKeys = Convert-RegToPSObject -regFilePath $($params.'RegistryFile') - } catch { - throw $_ + Default { + $templateObject.objectMap[$i].value = $($keyValue) } - # 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 - $newObject.Add($templateObject.objectMap[$i]) | Out-Null } - } - $updatedPolicyObject = $newObject | Select-Object configFieldID, configFieldName, value - } elseif ($values) { - $updatedPolicyObject = $values - } else { - if (($templateObject.objectMap).count -gt 0) { - $initialUserInput = Show-JCPolicyValues -policyObject $templateObject.objectMap - # User selects edit all fields - if ($initialUserInput.fieldSelection -eq 'A') { - for ($i = 0; $i -le $initialUserInput.fieldCount; $i++) { - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $i - } - # Display policy values - Show-JCPolicyValues -policyObject $updatedPolicyObject -ShowTable $true + $newObject.Add($templateObject.objectMap[$i]) | Out-Null + } elseif ('RegistryFile' -in $params.Keys) { + try { + $regKeys = Convert-RegToPSObject -regFilePath $($params.'RegistryFile') + } catch { + throw $_ } - # User selects edit individual field - elseif ($initialUserInput.fieldSelection -ne 'C' -or $initialUserInput.fieldSelection -ne 'A') { - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $initialUserInput.fieldSelection - Do { - # Hide option to edit all fields - $userInput = Show-JCPolicyValues -policyObject $updatedPolicyObject -HideAll $true - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $userInput.fieldSelection - } while ($userInput.fieldSelection -ne 'C') - } - $updatedPolicyObject = $updatedPolicyObject | Select-Object configFieldID, configFieldName, value + # 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 + $newObject.Add($templateObject.objectMap[$i]) | Out-Null } } - - # Validate PolicyObject - if ($updatedPolicyObject) { - $updatedPolicyObject | ForEach-Object { - # Check to see if value property is set, if not set to defaultValue - if ($_.value -eq $null) { - $_.value = $_.defaultValue + $updatedPolicyObject = $newObject | Select-Object configFieldID, configFieldName, value + } elseif ($values) { + $updatedPolicyObject = $values + } else { + if (($templateObject.objectMap).count -gt 0) { + $initialUserInput = Show-JCPolicyValues -policyObject $templateObject.objectMap + # User selects edit all fields + if ($initialUserInput.fieldSelection -eq 'A') { + for ($i = 0; $i -le $initialUserInput.fieldCount; $i++) { + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $i } + # Display policy values + Show-JCPolicyValues -policyObject $updatedPolicyObject -ShowTable $true } - $body = [PSCustomObject]@{ - name = $policyName - template = @{id = $templateID } - values = @($updatedPolicyObject) - } | ConvertTo-Json -Depth 99 - } else { - # for policies w/o payloads, just pass in the name & template - $body = [PSCustomObject]@{ - name = $policyName - template = @{id = $templateID } - } | ConvertTo-Json -Depth 99 + # User selects edit individual field + elseif ($initialUserInput.fieldSelection -ne 'C' -or $initialUserInput.fieldSelection -ne 'A') { + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $initialUserInput.fieldSelection + Do { + # Hide option to edit all fields + $userInput = Show-JCPolicyValues -policyObject $updatedPolicyObject -HideAll $true + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $userInput.fieldSelection + } while ($userInput.fieldSelection -ne 'C') + } + $updatedPolicyObject = $updatedPolicyObject | Select-Object configFieldID, configFieldName, value + } + } + # Validate PolicyObject + if ($updatedPolicyObject) { + $updatedPolicyObject | ForEach-Object { + # Check to see if value property is set, if not set to defaultValue + if ($_.value -eq $null) { + $_.value = $_.defaultValue + } } + $body = [PSCustomObject]@{ + name = $policyName + template = @{id = $templateID } + values = @($updatedPolicyObject) + } | ConvertTo-Json -Depth 99 + } else { + # for policies w/o payloads, just pass in the name & template + $body = [PSCustomObject]@{ + name = $policyName + template = @{id = $templateID } + } | 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 1ecdd726d..8e812e18f 100644 --- a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 +++ b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 @@ -23,9 +23,6 @@ function Set-JCPolicy { HelpMessage = 'The values object either built manually or passed in through Get-JCPolicy')] [System.object[]] $Values - # [Parameter(Mandatory = $false, - # HelpMessage = 'A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template.')] - # [System.IO.FileInfo]$registryFile ) DynamicParam { From 02d99a298b639914964758bf9d0fbd4f66a58ebc Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Wed, 19 Jul 2023 16:37:30 +0000 Subject: [PATCH 65/77] Updating PowerShell Module;[skip ci] --- .../JumpCloud Module/Docs/Set-JCPolicy.md | 21 ++--------- .../Docs/Set-JCSettingsFile.md | 2 +- PowerShell/JumpCloud Module/JumpCloud.psd1 | 2 +- .../JumpCloud Module/en-Us/JumpCloud-help.xml | 36 ------------------- 4 files changed, 4 insertions(+), 57 deletions(-) diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md b/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md index 8770dbc8f..5e2ff89fa 100644 --- a/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md +++ b/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md @@ -19,14 +19,12 @@ Set-JCPolicy can display the available parameters per policy if a `PolicyName` o ### ByID (Default) ``` -Set-JCPolicy -PolicyID [-NewName ] [-Values ] [-registryFile ] - [] +Set-JCPolicy -PolicyID [-NewName ] [-Values ] [] ``` ### ByName ``` -Set-JCPolicy -PolicyName [-NewName ] [-Values ] [-registryFile ] - [] +Set-JCPolicy -PolicyName [-NewName ] [-Values ] [] ``` ## DESCRIPTION @@ -124,21 +122,6 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -registryFile -A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template. - -```yaml -Type: System.IO.FileInfo -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ### -Values The values object either built manually or passed in through Get-JCPolicy diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md b/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md index ba6b37a0c..f8bf10130 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 [-moduleBannerMessageCount ] [-parallelOverride ] [] +Set-JCSettingsFile [-parallelOverride ] [-moduleBannerMessageCount ] [] ``` ## DESCRIPTION diff --git a/PowerShell/JumpCloud Module/JumpCloud.psd1 b/PowerShell/JumpCloud Module/JumpCloud.psd1 index 3bdf6bb81..f4164e15d 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: 7/18/2023 +# Generated on: 7/19/2023 # @{ diff --git a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml index ee7c6d2f3..92bb0cfd6 100644 --- a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml +++ b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml @@ -14856,18 +14856,6 @@ Enter a value between 1 and 2: None - - registryFile - - A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template. - - System.IO.FileInfo - - System.IO.FileInfo - - - None - Values @@ -14907,18 +14895,6 @@ Enter a value between 1 and 2: None - - registryFile - - A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template. - - System.IO.FileInfo - - System.IO.FileInfo - - - None - Values @@ -14970,18 +14946,6 @@ Enter a value between 1 and 2: None - - registryFile - - A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template. - - System.IO.FileInfo - - System.IO.FileInfo - - - None - Values From 33273b5154cfb359742b21b98aba3017cc44b0bb Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Thu, 20 Jul 2023 08:41:16 -0600 Subject: [PATCH 66/77] registryOverrwrite param, update tests, fix for single reg item file --- .../Policies/Convert-RegToPSObject.ps1 | 16 +++- .../Public/Policies/Set-JCPolicy.ps1 | 87 +++++++++++-------- .../Public/Policies/Set-JCPolicy.tests.ps1 | 13 +++ 3 files changed, 76 insertions(+), 40 deletions(-) diff --git a/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 b/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 index 2536f921c..88ccf81cc 100644 --- a/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 +++ b/PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1 @@ -53,7 +53,9 @@ function Convert-RegToPSObject { $customRegType = "QWORD" $value = ($valueObject[1]).Substring(7).split(",") # Convert to value - $value = for ($i = $value.count - 1; $i -ge 0; $i--) { $value[$i] } + $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):")) { @@ -61,7 +63,11 @@ function Convert-RegToPSObject { $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" } + if ($value[$i] -ne '00') { + [string][char][int]('0x' + $value[$i]) + } else { + "\0" + } } $customData = $value -join "" } elseif ($valueObject[1].StartsWith("hex(2):")) { @@ -69,7 +75,9 @@ function Convert-RegToPSObject { $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])} + if ($value[$i] -ne '00') { + [string][char][int]('0x' + $value[$i]) + } } $customData = $value -join "" } else { @@ -94,6 +102,6 @@ function Convert-RegToPSObject { } end { # Return objectarray containing keys - return $regKeys + return , $regKeys } } \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 index 8e812e18f..9918f2b43 100644 --- a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 +++ b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 @@ -109,6 +109,16 @@ function Set-JCPolicy { $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 @@ -225,8 +235,16 @@ function Set-JCPolicy { throw $_ } # Set the registryFile as the customRegTable - $templateObject.objectMap[0].value = $regKeys - $newObject.Add($templateObject.objectMap[0]) | Out-Null + 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 @@ -258,42 +276,31 @@ function Set-JCPolicy { } } else { if (($templateObject.objectMap).count -gt 0) { - if ($registryFile) { - $updatedPolicyObject = $foundPolicy.values - try { - $regKeys = Convert-RegToPSObject -regFilePath $registryFile - } catch { - throw $_ + # Begin user prompt + $initialUserInput = Show-JCPolicyValues -policyObject $templateObject.objectMap -policyValues $foundPolicy.values + # User selects edit all fields + if ($initialUserInput.fieldSelection -eq 'A') { + for ($i = 0; $i -le $initialUserInput.fieldCount; $i++) { + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $i -policyValues $foundPolicy.values } - $updatedPolicyObject.value += $regKeys - Write-Debug $updatedPolicyObject - } else { - # Begin user prompt - $initialUserInput = Show-JCPolicyValues -policyObject $templateObject.objectMap -policyValues $foundPolicy.values - # User selects edit all fields - if ($initialUserInput.fieldSelection -eq 'A') { - for ($i = 0; $i -le $initialUserInput.fieldCount; $i++) { - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $i -policyValues $foundPolicy.values - } - # Display policy values - # Show-JCPolicyValues -policyObject $updatedPolicyObject -ShowTable $true - } - # User selects edit individual field - elseif ($initialUserInput.fieldSelection -ne 'C' -or $initialUserInput.fieldSelection -ne 'A') { - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $initialUserInput.fieldSelection -policyValues $foundPolicy.values - # For set-jcpolicy, add the help & label options - $updatedPolicyObject | ForEach-Object { - if ($_.configFieldID -in $templateObject.objectMap.configFieldID) { - $_ | Add-Member -MemberType NoteProperty -Name "help" -Value $templateObject.objectMap[$templateObject.objectMap.configFieldID.IndexOf($($_.configFieldID))].help - $_ | Add-Member -MemberType NoteProperty -Name "label" -Value $templateObject.objectMap[$templateObject.objectMap.configFieldID.IndexOf($($_.configFieldID))].label - } + # Display policy values + # Show-JCPolicyValues -policyObject $updatedPolicyObject -ShowTable $true + } + # User selects edit individual field + elseif ($initialUserInput.fieldSelection -ne 'C' -or $initialUserInput.fieldSelection -ne 'A') { + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $initialUserInput.fieldSelection -policyValues $foundPolicy.values + # For set-jcpolicy, add the help & label options + $updatedPolicyObject | ForEach-Object { + if ($_.configFieldID -in $templateObject.objectMap.configFieldID) { + $_ | Add-Member -MemberType NoteProperty -Name "help" -Value $templateObject.objectMap[$templateObject.objectMap.configFieldID.IndexOf($($_.configFieldID))].help + $_ | Add-Member -MemberType NoteProperty -Name "label" -Value $templateObject.objectMap[$templateObject.objectMap.configFieldID.IndexOf($($_.configFieldID))].label } - Do { - # Hide option to edit all fields - $userInput = Show-JCPolicyValues -policyObject $updatedPolicyObject -HideAll $true -policyValues $foundPolicy.values - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $userInput.fieldSelection -policyValues $foundPolicy.values - } while ($userInput.fieldSelection -ne 'C') } + Do { + # Hide option to edit all fields + $userInput = Show-JCPolicyValues -policyObject $updatedPolicyObject -HideAll $true -policyValues $foundPolicy.values + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $userInput.fieldSelection -policyValues $foundPolicy.values + } while ($userInput.fieldSelection -ne 'C') } } } @@ -322,4 +329,12 @@ function Set-JCPolicy { end { return $response | Select-Object -Property "name", "id", "templateID", "values", "template" } -} \ No newline at end of file +} +$privs = Get-ChildItem -Path "/Users/jworkman/Documents/GitHub/support/PowerShell/JumpCloud Module/Private" -recurse -Filter *.ps1 +foreach ($privFunc in $privs) { + write-host "importing $($privFunc.FullName)" + . "$($privFunc.FullName)" +} +# "/Users/jworkman/Downloads/hey.reg" +# "/Users/jworkman/Documents/GitHub/support/PowerShell/JumpCloud Module/Tests/Reg_File/PesterRegFile.reg" +Set-JCPolicy -PolicyID 64b82ddb6e220b0001d17889 -RegistryFile /Users/jworkman/Downloads/hey.reg -RegistryOverwrite \ No newline at end of file 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 8e3251b66..eb4449109 100644 --- a/PowerShell/JumpCloud Module/Tests/Public/Policies/Set-JCPolicy.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Policies/Set-JCPolicy.tests.ps1 @@ -466,6 +466,19 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' { $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 From b7c46176d810ed189e4343f7975033d86986e1bc Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Thu, 20 Jul 2023 09:13:23 -0600 Subject: [PATCH 67/77] remove testing vars --- .../JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 | 8 -------- 1 file changed, 8 deletions(-) diff --git a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 index 9918f2b43..b6941c83a 100644 --- a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 +++ b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 @@ -330,11 +330,3 @@ function Set-JCPolicy { return $response | Select-Object -Property "name", "id", "templateID", "values", "template" } } -$privs = Get-ChildItem -Path "/Users/jworkman/Documents/GitHub/support/PowerShell/JumpCloud Module/Private" -recurse -Filter *.ps1 -foreach ($privFunc in $privs) { - write-host "importing $($privFunc.FullName)" - . "$($privFunc.FullName)" -} -# "/Users/jworkman/Downloads/hey.reg" -# "/Users/jworkman/Documents/GitHub/support/PowerShell/JumpCloud Module/Tests/Reg_File/PesterRegFile.reg" -Set-JCPolicy -PolicyID 64b82ddb6e220b0001d17889 -RegistryFile /Users/jworkman/Downloads/hey.reg -RegistryOverwrite \ No newline at end of file From 7eca361556d8e3b923a5a10ede71d778be1e056b Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Thu, 20 Jul 2023 15:22:08 +0000 Subject: [PATCH 68/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- PowerShell/JumpCloud Module/JumpCloud.psd1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerShell/JumpCloud Module/JumpCloud.nuspec b/PowerShell/JumpCloud Module/JumpCloud.nuspec index 4b47f16bc..5fc798c6c 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.7.0.9224-202307171629 + 2.7.0.9281-202307201520 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 f4164e15d..e487a0235 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: 7/19/2023 +# Generated on: 7/20/2023 # @{ From 48415c6a6cea10510b7a31ac8088fa80d9bc9899 Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Thu, 20 Jul 2023 11:18:14 -0600 Subject: [PATCH 69/77] Throw error when policy with multiple names are matched w/ policyName parameter --- .../Public/Policies/Set-JCPolicy.ps1 | 504 +++++++++--------- .../Public/Policies/Set-JCPolicy.tests.ps1 | 10 + 2 files changed, 266 insertions(+), 248 deletions(-) diff --git a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 index b6941c83a..160567b63 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,288 +48,293 @@ function Set-JCPolicy { if ([string]::IsNullOrEmpty($foundPolicy.ID)) { throw "Could not find policy by specified Name" } - } - # If policy is identified, get the dynamic policy set - if ($foundPolicy.id -And ($PSBoundParameters["PolicyName"] -OR $PSBoundParameters["PolicyID"])) { - # Set the policy template object based on policy - $templateObject = Get-JCPolicyTemplateConfigField -templateID $foundPolicy.Template.Id - $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary - # Foreach key in the supplied config file: - foreach ($key in $templateObject.objectMap) { - # Set the dynamic parameters' name - $ParamName_Filter = "$($key.configFieldName)" - # Create the collection of attributes - $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] - # If ValidateSet is specified in the config file, set the value here: - # If the type of value is a bool, create a custom validateSet attribute here: - $paramType = $($key.type) - switch ($paramType) { - 'boolean' { - $arrSet = @("true", "false") - $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) - $AttributeCollection.Add($ValidateSetAttribute) - } - 'multi' { - $paramType = 'string' - $arrSet = $key.validation.values - $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) - $AttributeCollection.Add($ValidateSetAttribute) - } - 'file' { - $paramType = 'string' - } - 'listbox' { - $paramType = [system.string[]] + 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"])) { + # Set the policy template object based on policy + $templateObject = Get-JCPolicyTemplateConfigField -templateID $foundPolicy.Template.Id + $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary + # Foreach key in the supplied config file: + foreach ($key in $templateObject.objectMap) { + # Set the dynamic parameters' name + $ParamName_Filter = "$($key.configFieldName)" + # Create the collection of attributes + $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] + # If ValidateSet is specified in the config file, set the value here: + # If the type of value is a bool, create a custom validateSet attribute here: + $paramType = $($key.type) + switch ($paramType) { + 'boolean' { + $arrSet = @("true", "false") + $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) + $AttributeCollection.Add($ValidateSetAttribute) + } + 'multi' { + $paramType = 'string' + $arrSet = $key.validation.values + $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) + $AttributeCollection.Add($ValidateSetAttribute) + } + 'file' { + $paramType = 'string' + } + 'listbox' { + $paramType = [system.string[]] + } + 'table' { + $paramType = [system.object[]] + } + 'exclude' { + Continue + } + Default { + $paramType = 'string' + } } - 'table' { - $paramType = [system.object[]] + # Set the help message + if ([String]::isNullorEmpty($($key.help))) { + $ParameterAttribute.HelpMessage = "sets the value for the $($key.name) field" + } else { + $ParameterAttribute.HelpMessage = "$($key.help)" } - 'exclude' { - Continue + # Add the attributes to the attributes collection + $AttributeCollection.Add($ParameterAttribute) + # 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) } - Default { - $paramType = 'string' + 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) } } - # Set the help message - if ([String]::isNullorEmpty($($key.help))) { - $ParameterAttribute.HelpMessage = "sets the value for the $($key.name) field" - } else { - $ParameterAttribute.HelpMessage = "$($key.help)" - } - # Add the attributes to the attributes collection - $AttributeCollection.Add($ParameterAttribute) - # 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 } - # Returns the dictionary - return $RuntimeParameterDictionary - } - } - begin { - Write-Debug 'Verifying JCAPI Key' - if ($JCAPIKEY.length -ne 40) { - Connect-JCOnline } - } - process { - # Get Existing Policy Data if not set through dynamic param - if (([string]::IsNullOrEmpty($foundPolicy.ID)) -And ($policyID)) { - # Get the policy by ID - $foundPolicy = Get-JCPolicy -PolicyID $PolicyID - if ([string]::IsNullOrEmpty($foundPolicy.ID)) { - throw "Could not find policy by ID" + begin { + Write-Debug 'Verifying JCAPI Key' + if ($JCAPIKEY.length -ne 40) { + Connect-JCOnline } } - $templateObject = Get-JCPolicyTemplateConfigField -templateID $foundPolicy.Template.Id - # First set the name from PSParamSet if set; else set from policy - $policyNameFromProcess = if ($PSBoundParameters["NewName"]) { - $NewName - } else { - $foundPolicy.name - } - $params = $PSBoundParameters - $paramterSet = $params.keys - $DynamicParamSet = $false - $requiredSet = @('PolicyID', 'PolicyName', 'NewName' , 'Values') - foreach ($parameter in $paramterSet) { - $parameterComparison = Compare-Object -ReferenceObject $requiredSet -DifferenceObject $parameter - if ($parameterComparison | Where-Object { $_.sideindicator -eq "=>" }) { - $DynamicParamSet = $true - break + process { + # Get Existing Policy Data if not set through dynamic param + if (([string]::IsNullOrEmpty($foundPolicy.ID)) -And ($policyID)) { + # Get the policy by ID + $foundPolicy = Get-JCPolicy -PolicyID $PolicyID + 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" + } } - } - if ($DynamicParamSet) { - # begin dynamic param set - $newObject = New-Object System.Collections.ArrayList - for ($i = 0; $i -lt $templateObject.objectMap.count; $i++) { - # If one of the dynamicParam config fields are passed in and is found in the policy template, set the new value: - if ($templateObject.objectMap[$i].configFieldName -in $params.keys) { - $keyName = $params.keys | Where-Object { $_ -eq $templateObject.objectMap[$i].configFieldName } - # write-host "Setting value from $($keyName)" - $keyValue = $params.$KeyName - switch ($templateObject.objectMap[$i].type) { - 'multi' { - $templateObject.objectMap[$i].value = $(($templateObject.objectMap[$i].validation | Where-Object { $_.Values -eq $keyValue }).keys) - } - 'file' { - $path = Test-Path -Path $keyValue - if ($path) { - # convert file path to base64 string - $templateObject.objectMap[$i].value = [convert]::ToBase64String((Get-Content -Path $keyValue -AsByteStream)) + $templateObject = Get-JCPolicyTemplateConfigField -templateID $foundPolicy.Template.Id + # First set the name from PSParamSet if set; else set from policy + $policyNameFromProcess = if ($PSBoundParameters["NewName"]) { + $NewName + } else { + $foundPolicy.name + } + $params = $PSBoundParameters + $paramterSet = $params.keys + $DynamicParamSet = $false + $requiredSet = @('PolicyID', 'PolicyName', 'NewName' , 'Values') + foreach ($parameter in $paramterSet) { + $parameterComparison = Compare-Object -ReferenceObject $requiredSet -DifferenceObject $parameter + if ($parameterComparison | Where-Object { $_.sideindicator -eq "=>" }) { + $DynamicParamSet = $true + break + } + } + if ($DynamicParamSet) { + # begin dynamic param set + $newObject = New-Object System.Collections.ArrayList + for ($i = 0; $i -lt $templateObject.objectMap.count; $i++) { + # If one of the dynamicParam config fields are passed in and is found in the policy template, set the new value: + if ($templateObject.objectMap[$i].configFieldName -in $params.keys) { + $keyName = $params.keys | Where-Object { $_ -eq $templateObject.objectMap[$i].configFieldName } + # write-host "Setting value from $($keyName)" + $keyValue = $params.$KeyName + switch ($templateObject.objectMap[$i].type) { + 'multi' { + $templateObject.objectMap[$i].value = $(($templateObject.objectMap[$i].validation | Where-Object { $_.Values -eq $keyValue }).keys) } - #TODO: else we should throw an error here that the file path was not valid - } - 'listbox' { - if ($($keyValue).getType().name -eq 'String') { - # Given case for single string passed in as dynamic input, convert to a list - $listRows = New-Object System.Collections.ArrayList - foreach ($regItem in $keyValue) { - $listRows.Add($regItem) + 'file' { + $path = Test-Path -Path $keyValue + if ($path) { + # convert file path to base64 string + $templateObject.objectMap[$i].value = [convert]::ToBase64String((Get-Content -Path $keyValue -AsByteStream)) } - $templateObject.objectMap[$i].value = $listRows - } elseif ($($keyValue).getType().name -eq 'Object[]') { - # else if the object passed in is a list already, pass in list - $templateObject.objectMap[$i].value = $($keyValue) + #TODO: else we should throw an error here that the file path was not valid } - } - 'table' { - # For custom registry table, validate the object - if ($templateObject.objectMap[$i].configFieldName -eq "customRegTable") { - # get default value properties - $RegProperties = $templateObject.objectMap[$i].defaultValue | Get-Member -MemberType NoteProperty - # get passed in object properties - $ObjectProperties = if ($keyValue | Get-Member -MemberType NoteProperty) { - # for lists get note properties - ($keyValue | Get-Member -MemberType NoteProperty).Name - } else { - # for single objects, get keys - $keyValue.keys - } - $RegProperties | ForEach-Object { - if ($_.Name -notin $ObjectProperties) { - Throw "Custom Registry Tables require a `"$($_.Name)`" data string. The following data types were found: $($ObjectProperties)" + 'listbox' { + if ($($keyValue).getType().name -eq 'String') { + # Given case for single string passed in as dynamic input, convert to a list + $listRows = New-Object System.Collections.ArrayList + foreach ($regItem in $keyValue) { + $listRows.Add($regItem) } + $templateObject.objectMap[$i].value = $listRows + } elseif ($($keyValue).getType().name -eq 'Object[]') { + # else if the object passed in is a list already, pass in list + $templateObject.objectMap[$i].value = $($keyValue) } - # reg type validation - $validRegTypes = @('DWORD', 'expandString', 'multiString', 'QWORD', 'String') - $($keyValue).customRegType | ForEach-Object { - if ($_ -notin $validRegTypes) { - throw "Custom Registry Tables require the `"customRegType`" data string to be one of: $validRegTypes, found: $_" + } + 'table' { + # For custom registry table, validate the object + if ($templateObject.objectMap[$i].configFieldName -eq "customRegTable") { + # get default value properties + $RegProperties = $templateObject.objectMap[$i].defaultValue | Get-Member -MemberType NoteProperty + # get passed in object properties + $ObjectProperties = if ($keyValue | Get-Member -MemberType NoteProperty) { + # for lists get note properties + ($keyValue | Get-Member -MemberType NoteProperty).Name + } else { + # for single objects, get keys + $keyValue.keys + } + $RegProperties | ForEach-Object { + if ($_.Name -notin $ObjectProperties) { + Throw "Custom Registry Tables require a `"$($_.Name)`" data string. The following data types were found: $($ObjectProperties)" + } + } + # reg type validation + $validRegTypes = @('DWORD', 'expandString', 'multiString', 'QWORD', 'String') + $($keyValue).customRegType | ForEach-Object { + if ($_ -notin $validRegTypes) { + throw "Custom Registry Tables require the `"customRegType`" data string to be one of: $validRegTypes, found: $_" + } } } + $regRows = New-Object System.Collections.ArrayList + foreach ($regItem in $keyValue) { + $regRows.Add($regItem) | Out-Null + } + $templateObject.objectMap[$i].value = $regRows } - $regRows = New-Object System.Collections.ArrayList - foreach ($regItem in $keyValue) { - $regRows.Add($regItem) | Out-Null + Default { + $templateObject.objectMap[$i].value = $($keyValue) } - $templateObject.objectMap[$i].value = $regRows } - Default { - $templateObject.objectMap[$i].value = $($keyValue) + $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 + $newObject.Add($templateObject.objectMap[$i]) | Out-Null } - $newObject.Add($templateObject.objectMap[$i]) | Out-Null - } elseif ('RegistryFile' -in $params.Keys) { + } + $updatedPolicyObject = $newObject | Select-Object configFieldID, configFieldName, value + if ($registryFile) { try { - $regKeys = Convert-RegToPSObject -regFilePath $($params.'RegistryFile') + $regKeys = Convert-RegToPSObject -regFilePath $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 - $newObject.Add($templateObject.objectMap[$i]) | Out-Null + $updatedPolicyObject.value += $regKeys + Write-Debug $updatedPolicyObject } - } - $updatedPolicyObject = $newObject | Select-Object configFieldID, configFieldName, value - if ($registryFile) { - try { - $regKeys = Convert-RegToPSObject -regFilePath $registryFile - } catch { - throw $_ + } elseif ($values) { + # begin value param set + $updatedPolicyObject = New-Object System.Collections.ArrayList + # Add each value into the object to set the policy + foreach ($value in $values) { + $updatedPolicyObject.add($value) | Out-Null } - $updatedPolicyObject.value += $regKeys - Write-Debug $updatedPolicyObject - } - } elseif ($values) { - # begin value param set - $updatedPolicyObject = New-Object System.Collections.ArrayList - # Add each value into the object to set the policy - foreach ($value in $values) { - $updatedPolicyObject.add($value) | Out-Null - } - # If only one or a few of the config fields were set, add the remaining items from $foundPolicy.values - $foundPolicy.values | ForEach-Object { - if ($_.configFieldID -notin $updatedPolicyObject.configFieldID) { - $updatedPolicyObject.Add($_) | Out-Null - } - } - } else { - if (($templateObject.objectMap).count -gt 0) { - # Begin user prompt - $initialUserInput = Show-JCPolicyValues -policyObject $templateObject.objectMap -policyValues $foundPolicy.values - # User selects edit all fields - if ($initialUserInput.fieldSelection -eq 'A') { - for ($i = 0; $i -le $initialUserInput.fieldCount; $i++) { - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $i -policyValues $foundPolicy.values + # If only one or a few of the config fields were set, add the remaining items from $foundPolicy.values + $foundPolicy.values | ForEach-Object { + if ($_.configFieldID -notin $updatedPolicyObject.configFieldID) { + $updatedPolicyObject.Add($_) | Out-Null } - # Display policy values - # Show-JCPolicyValues -policyObject $updatedPolicyObject -ShowTable $true } - # User selects edit individual field - elseif ($initialUserInput.fieldSelection -ne 'C' -or $initialUserInput.fieldSelection -ne 'A') { - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $initialUserInput.fieldSelection -policyValues $foundPolicy.values - # For set-jcpolicy, add the help & label options - $updatedPolicyObject | ForEach-Object { - if ($_.configFieldID -in $templateObject.objectMap.configFieldID) { - $_ | Add-Member -MemberType NoteProperty -Name "help" -Value $templateObject.objectMap[$templateObject.objectMap.configFieldID.IndexOf($($_.configFieldID))].help - $_ | Add-Member -MemberType NoteProperty -Name "label" -Value $templateObject.objectMap[$templateObject.objectMap.configFieldID.IndexOf($($_.configFieldID))].label + } else { + if (($templateObject.objectMap).count -gt 0) { + # Begin user prompt + $initialUserInput = Show-JCPolicyValues -policyObject $templateObject.objectMap -policyValues $foundPolicy.values + # User selects edit all fields + if ($initialUserInput.fieldSelection -eq 'A') { + for ($i = 0; $i -le $initialUserInput.fieldCount; $i++) { + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $i -policyValues $foundPolicy.values } + # Display policy values + # Show-JCPolicyValues -policyObject $updatedPolicyObject -ShowTable $true + } + # User selects edit individual field + elseif ($initialUserInput.fieldSelection -ne 'C' -or $initialUserInput.fieldSelection -ne 'A') { + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $initialUserInput.fieldSelection -policyValues $foundPolicy.values + # For set-jcpolicy, add the help & label options + $updatedPolicyObject | ForEach-Object { + if ($_.configFieldID -in $templateObject.objectMap.configFieldID) { + $_ | Add-Member -MemberType NoteProperty -Name "help" -Value $templateObject.objectMap[$templateObject.objectMap.configFieldID.IndexOf($($_.configFieldID))].help + $_ | Add-Member -MemberType NoteProperty -Name "label" -Value $templateObject.objectMap[$templateObject.objectMap.configFieldID.IndexOf($($_.configFieldID))].label + } + } + Do { + # Hide option to edit all fields + $userInput = Show-JCPolicyValues -policyObject $updatedPolicyObject -HideAll $true -policyValues $foundPolicy.values + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $userInput.fieldSelection -policyValues $foundPolicy.values + } while ($userInput.fieldSelection -ne 'C') } - Do { - # Hide option to edit all fields - $userInput = Show-JCPolicyValues -policyObject $updatedPolicyObject -HideAll $true -policyValues $foundPolicy.values - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $userInput.fieldSelection -policyValues $foundPolicy.values - } while ($userInput.fieldSelection -ne 'C') } } + if ($updatedPolicyObject) { + $body = [PSCustomObject]@{ + name = $policyNameFromProcess + template = @{id = $foundPolicy.Template.Id } + values = @($updatedPolicyObject) + } | ConvertTo-Json -Depth 99 + } else { + $body = [PSCustomObject]@{ + name = $policyNameFromProcess + template = @{id = $foundPolicy.Template.Id } + } | ConvertTo-Json -Depth 99 + } + $headers = @{ + 'x-api-key' = $env:JCApiKey + 'x-org-id' = $env:JCOrgId + 'content-type' = "application/json" + } + $response = Invoke-RestMethod -Uri "https://console.jumpcloud.com/api/v2/policies/$($foundPolicy.id)" -Method PUT -Headers $headers -ContentType 'application/json' -Body $body + if ($response) { + $response | Add-Member -MemberType NoteProperty -Name "templateID" -Value $response.template.id + } } - if ($updatedPolicyObject) { - $body = [PSCustomObject]@{ - name = $policyNameFromProcess - template = @{id = $foundPolicy.Template.Id } - values = @($updatedPolicyObject) - } | ConvertTo-Json -Depth 99 - } else { - $body = [PSCustomObject]@{ - name = $policyNameFromProcess - template = @{id = $foundPolicy.Template.Id } - } | ConvertTo-Json -Depth 99 - } - $headers = @{ - 'x-api-key' = $env:JCApiKey - 'x-org-id' = $env:JCOrgId - 'content-type' = "application/json" - } - $response = Invoke-RestMethod -Uri "https://console.jumpcloud.com/api/v2/policies/$($foundPolicy.id)" -Method PUT -Headers $headers -ContentType 'application/json' -Body $body - if ($response) { - $response | Add-Member -MemberType NoteProperty -Name "templateID" -Value $response.template.id + end { + return $response | Select-Object -Property "name", "id", "templateID", "values", "template" } } - end { - return $response | Select-Object -Property "name", "id", "templateID", "values", "template" - } -} 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 eb4449109..96133047b 100644 --- a/PowerShell/JumpCloud Module/Tests/Public/Policies/Set-JCPolicy.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Policies/Set-JCPolicy.tests.ps1 @@ -452,6 +452,16 @@ Describe -Tag:('JCPolicy') 'Set-JCPolicy' { $usbLinuxPolicyUpdated.templateID | Should -Not -BeNullOrEmpty } } + 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 From 9e3e7920392438a10aa3eaf4d9d192bf11f13226 Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Thu, 20 Jul 2023 12:36:25 -0600 Subject: [PATCH 70/77] documentation [skip ci] --- .../JumpCloud Module/Docs/New-JCPolicy.md | 12 ++++++++++ .../JumpCloud Module/Docs/Set-JCPolicy.md | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md b/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md index 0c5eb8b6f..cdd008ab6 100644 --- a/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md +++ b/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md @@ -18,11 +18,13 @@ At a minimum to display the dynamic set of parameters per template, the `Templat ## SYNTAX ### ByID (Default) + ``` New-JCPolicy -TemplateID [-Name ] [-Values ] [] ``` ### ByName + ``` New-JCPolicy -TemplateName [-Name ] [-Values ] [] ``` @@ -72,6 +74,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 @@ -139,6 +149,7 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS @@ -150,6 +161,7 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## OUTPUTS ### System.Object + ## NOTES ## RELATED LINKS diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md b/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md index 5e2ff89fa..3659fd6ee 100644 --- a/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md +++ b/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md @@ -18,11 +18,13 @@ Set-JCPolicy can display the available parameters per policy if a `PolicyName` o ## SYNTAX ### ByID (Default) + ``` Set-JCPolicy -PolicyID [-NewName ] [-Values ] [] ``` ### ByName + ``` Set-JCPolicy -PolicyName [-NewName ] [-Values ] [] ``` @@ -72,6 +74,24 @@ 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 @@ -139,6 +159,7 @@ Accept wildcard characters: False ``` ### CommonParameters + This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS @@ -150,6 +171,7 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## OUTPUTS ### System.Object + ## NOTES ## RELATED LINKS From 12f31cc67dfea342d885c33313961639f59f1748 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Mon, 31 Jul 2023 14:06:50 -0600 Subject: [PATCH 71/77] fix closing {} --- PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 index 160567b63..5b4e0bf29 100644 --- a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 +++ b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 @@ -338,3 +338,4 @@ function Set-JCPolicy { return $response | Select-Object -Property "name", "id", "templateID", "values", "template" } } +} From 4f13c66ccca7c7caa4fef249f2aa49c88d3e1aa4 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Mon, 31 Jul 2023 14:16:40 -0600 Subject: [PATCH 72/77] fix doc headers --- PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md b/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md index 3659fd6ee..d637df858 100644 --- a/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md +++ b/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md @@ -74,7 +74,7 @@ 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 +### Example 5 ```powershell PS C:\> Set-JCPolicy -PolicyName "Windows - Imported Custom Registry Settings" -RegistryFile "/path/to/registryFile.reg" @@ -83,7 +83,7 @@ PS C:\> Set-JCPolicy -PolicyName "Windows - Imported Custom Registry Settings" 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 +### Example 6 ```powershell PS C:\> Set-JCPolicy -PolicyName "Windows - Imported Custom Registry Settings" -RegistryFile "/path/to/registryFile.reg" -RegistryOverwrite From d8154ad4e75a2937aab0449d1415c169149ad761 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Mon, 31 Jul 2023 20:22:57 +0000 Subject: [PATCH 73/77] Updating PowerShell Module;[skip ci] --- .../JumpCloud Module/Docs/New-JCPolicy.md | 4 ---- .../JumpCloud Module/Docs/Set-JCPolicy.md | 6 ------ .../Docs/Set-JCSettingsFile.md | 2 +- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- PowerShell/JumpCloud Module/JumpCloud.psd1 | 2 +- .../JumpCloud Module/en-Us/JumpCloud-help.xml | 21 +++++++++++++++++++ 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md b/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md index cdd008ab6..2567c1d72 100644 --- a/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md +++ b/PowerShell/JumpCloud Module/Docs/New-JCPolicy.md @@ -18,13 +18,11 @@ At a minimum to display the dynamic set of parameters per template, the `Templat ## SYNTAX ### ByID (Default) - ``` New-JCPolicy -TemplateID [-Name ] [-Values ] [] ``` ### ByName - ``` New-JCPolicy -TemplateName [-Name ] [-Values ] [] ``` @@ -149,7 +147,6 @@ Accept wildcard characters: False ``` ### CommonParameters - This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS @@ -161,7 +158,6 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## OUTPUTS ### System.Object - ## NOTES ## RELATED LINKS diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md b/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md index d637df858..c307cd146 100644 --- a/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md +++ b/PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md @@ -18,13 +18,11 @@ Set-JCPolicy can display the available parameters per policy if a `PolicyName` o ## SYNTAX ### ByID (Default) - ``` Set-JCPolicy -PolicyID [-NewName ] [-Values ] [] ``` ### ByName - ``` Set-JCPolicy -PolicyName [-NewName ] [-Values ] [] ``` @@ -78,7 +76,6 @@ This would update the policy named `macOS - Login Window Policy` with the login ```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. @@ -87,7 +84,6 @@ This command would append the registry policy's existing values with the importe ```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. @@ -159,7 +155,6 @@ Accept wildcard characters: False ``` ### CommonParameters - This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS @@ -171,7 +166,6 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## OUTPUTS ### System.Object - ## NOTES ## RELATED LINKS 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 5fc798c6c..430feefe0 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.7.0.9281-202307201520 + 2.7.0.9314-202307312021 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 6eeb303bf..d2085dc66 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: 7/20/2023 +# Generated on: 7/31/2023 # @{ 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. + + From 3439a413b4161fd94a76ac874876be1a43594a13 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Tue, 1 Aug 2023 10:08:27 -0600 Subject: [PATCH 74/77] dynamicparam not closed correctly --- .../Public/Policies/Set-JCPolicy.ps1 | 356 +++++++++--------- 1 file changed, 178 insertions(+), 178 deletions(-) diff --git a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 index 5b4e0bf29..b51b764ac 100644 --- a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 +++ b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 @@ -129,213 +129,213 @@ function Set-JCPolicy { return $RuntimeParameterDictionary } } - begin { - Write-Debug 'Verifying JCAPI Key' - if ($JCAPIKEY.length -ne 40) { - Connect-JCOnline - } + } + begin { + Write-Debug 'Verifying JCAPI Key' + if ($JCAPIKEY.length -ne 40) { + Connect-JCOnline } - process { - # Get Existing Policy Data if not set through dynamic param - if (([string]::IsNullOrEmpty($foundPolicy.ID)) -And ($policyID)) { - # Get the policy by ID - $foundPolicy = Get-JCPolicy -PolicyID $PolicyID - 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" - } + } + process { + # Get Existing Policy Data if not set through dynamic param + if (([string]::IsNullOrEmpty($foundPolicy.ID)) -And ($policyID)) { + # Get the policy by ID + $foundPolicy = Get-JCPolicy -PolicyID $PolicyID + if ([string]::IsNullOrEmpty($foundPolicy.ID)) { + throw "Could not find policy by ID" } - $templateObject = Get-JCPolicyTemplateConfigField -templateID $foundPolicy.Template.Id - # First set the name from PSParamSet if set; else set from policy - $policyNameFromProcess = if ($PSBoundParameters["NewName"]) { - $NewName - } else { - $foundPolicy.name + if (($foundPolicy.ID).count -gt 1) { + throw "multiple policies with the same name were found, please specify a policy by ID" } - $params = $PSBoundParameters - $paramterSet = $params.keys - $DynamicParamSet = $false - $requiredSet = @('PolicyID', 'PolicyName', 'NewName' , 'Values') - foreach ($parameter in $paramterSet) { - $parameterComparison = Compare-Object -ReferenceObject $requiredSet -DifferenceObject $parameter - if ($parameterComparison | Where-Object { $_.sideindicator -eq "=>" }) { - $DynamicParamSet = $true - break - } + } + $templateObject = Get-JCPolicyTemplateConfigField -templateID $foundPolicy.Template.Id + # First set the name from PSParamSet if set; else set from policy + $policyNameFromProcess = if ($PSBoundParameters["NewName"]) { + $NewName + } else { + $foundPolicy.name + } + $params = $PSBoundParameters + $paramterSet = $params.keys + $DynamicParamSet = $false + $requiredSet = @('PolicyID', 'PolicyName', 'NewName' , 'Values') + foreach ($parameter in $paramterSet) { + $parameterComparison = Compare-Object -ReferenceObject $requiredSet -DifferenceObject $parameter + if ($parameterComparison | Where-Object { $_.sideindicator -eq "=>" }) { + $DynamicParamSet = $true + break } - if ($DynamicParamSet) { - # begin dynamic param set - $newObject = New-Object System.Collections.ArrayList - for ($i = 0; $i -lt $templateObject.objectMap.count; $i++) { - # If one of the dynamicParam config fields are passed in and is found in the policy template, set the new value: - if ($templateObject.objectMap[$i].configFieldName -in $params.keys) { - $keyName = $params.keys | Where-Object { $_ -eq $templateObject.objectMap[$i].configFieldName } - # write-host "Setting value from $($keyName)" - $keyValue = $params.$KeyName - switch ($templateObject.objectMap[$i].type) { - 'multi' { - $templateObject.objectMap[$i].value = $(($templateObject.objectMap[$i].validation | Where-Object { $_.Values -eq $keyValue }).keys) - } - 'file' { - $path = Test-Path -Path $keyValue - if ($path) { - # convert file path to base64 string - $templateObject.objectMap[$i].value = [convert]::ToBase64String((Get-Content -Path $keyValue -AsByteStream)) - } - #TODO: else we should throw an error here that the file path was not valid + } + if ($DynamicParamSet) { + # begin dynamic param set + $newObject = New-Object System.Collections.ArrayList + for ($i = 0; $i -lt $templateObject.objectMap.count; $i++) { + # If one of the dynamicParam config fields are passed in and is found in the policy template, set the new value: + if ($templateObject.objectMap[$i].configFieldName -in $params.keys) { + $keyName = $params.keys | Where-Object { $_ -eq $templateObject.objectMap[$i].configFieldName } + # write-host "Setting value from $($keyName)" + $keyValue = $params.$KeyName + switch ($templateObject.objectMap[$i].type) { + 'multi' { + $templateObject.objectMap[$i].value = $(($templateObject.objectMap[$i].validation | Where-Object { $_.Values -eq $keyValue }).keys) + } + 'file' { + $path = Test-Path -Path $keyValue + if ($path) { + # convert file path to base64 string + $templateObject.objectMap[$i].value = [convert]::ToBase64String((Get-Content -Path $keyValue -AsByteStream)) } - 'listbox' { - if ($($keyValue).getType().name -eq 'String') { - # Given case for single string passed in as dynamic input, convert to a list - $listRows = New-Object System.Collections.ArrayList - foreach ($regItem in $keyValue) { - $listRows.Add($regItem) - } - $templateObject.objectMap[$i].value = $listRows - } elseif ($($keyValue).getType().name -eq 'Object[]') { - # else if the object passed in is a list already, pass in list - $templateObject.objectMap[$i].value = $($keyValue) + #TODO: else we should throw an error here that the file path was not valid + } + 'listbox' { + if ($($keyValue).getType().name -eq 'String') { + # Given case for single string passed in as dynamic input, convert to a list + $listRows = New-Object System.Collections.ArrayList + foreach ($regItem in $keyValue) { + $listRows.Add($regItem) } + $templateObject.objectMap[$i].value = $listRows + } elseif ($($keyValue).getType().name -eq 'Object[]') { + # else if the object passed in is a list already, pass in list + $templateObject.objectMap[$i].value = $($keyValue) } - 'table' { - # For custom registry table, validate the object - if ($templateObject.objectMap[$i].configFieldName -eq "customRegTable") { - # get default value properties - $RegProperties = $templateObject.objectMap[$i].defaultValue | Get-Member -MemberType NoteProperty - # get passed in object properties - $ObjectProperties = if ($keyValue | Get-Member -MemberType NoteProperty) { - # for lists get note properties + } + 'table' { + # For custom registry table, validate the object + if ($templateObject.objectMap[$i].configFieldName -eq "customRegTable") { + # get default value properties + $RegProperties = $templateObject.objectMap[$i].defaultValue | Get-Member -MemberType NoteProperty + # get passed in object properties + $ObjectProperties = if ($keyValue | Get-Member -MemberType NoteProperty) { + # for lists get note properties ($keyValue | Get-Member -MemberType NoteProperty).Name - } else { - # for single objects, get keys - $keyValue.keys - } - $RegProperties | ForEach-Object { - if ($_.Name -notin $ObjectProperties) { - Throw "Custom Registry Tables require a `"$($_.Name)`" data string. The following data types were found: $($ObjectProperties)" - } - } - # reg type validation - $validRegTypes = @('DWORD', 'expandString', 'multiString', 'QWORD', 'String') - $($keyValue).customRegType | ForEach-Object { - if ($_ -notin $validRegTypes) { - throw "Custom Registry Tables require the `"customRegType`" data string to be one of: $validRegTypes, found: $_" - } + } else { + # for single objects, get keys + $keyValue.keys + } + $RegProperties | ForEach-Object { + if ($_.Name -notin $ObjectProperties) { + Throw "Custom Registry Tables require a `"$($_.Name)`" data string. The following data types were found: $($ObjectProperties)" } } - $regRows = New-Object System.Collections.ArrayList - foreach ($regItem in $keyValue) { - $regRows.Add($regItem) | Out-Null + # reg type validation + $validRegTypes = @('DWORD', 'expandString', 'multiString', 'QWORD', 'String') + $($keyValue).customRegType | ForEach-Object { + if ($_ -notin $validRegTypes) { + throw "Custom Registry Tables require the `"customRegType`" data string to be one of: $validRegTypes, found: $_" + } } - $templateObject.objectMap[$i].value = $regRows } - Default { - $templateObject.objectMap[$i].value = $($keyValue) + $regRows = New-Object System.Collections.ArrayList + foreach ($regItem in $keyValue) { + $regRows.Add($regItem) | Out-Null } + $templateObject.objectMap[$i].value = $regRows } - $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 + Default { + $templateObject.objectMap[$i].value = $($keyValue) } - } 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 - $newObject.Add($templateObject.objectMap[$i]) | Out-Null } - } - $updatedPolicyObject = $newObject | Select-Object configFieldID, configFieldName, value - if ($registryFile) { + $newObject.Add($templateObject.objectMap[$i]) | Out-Null + } elseif ('RegistryFile' -in $params.Keys) { try { - $regKeys = Convert-RegToPSObject -regFilePath $registryFile + $regKeys = Convert-RegToPSObject -regFilePath $($params.'RegistryFile') } catch { throw $_ } - $updatedPolicyObject.value += $regKeys - Write-Debug $updatedPolicyObject + # 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 + $newObject.Add($templateObject.objectMap[$i]) | Out-Null + } + } + $updatedPolicyObject = $newObject | Select-Object configFieldID, configFieldName, value + if ($registryFile) { + try { + $regKeys = Convert-RegToPSObject -regFilePath $registryFile + } catch { + throw $_ } - } elseif ($values) { - # begin value param set - $updatedPolicyObject = New-Object System.Collections.ArrayList - # Add each value into the object to set the policy - foreach ($value in $values) { - $updatedPolicyObject.add($value) | Out-Null + $updatedPolicyObject.value += $regKeys + Write-Debug $updatedPolicyObject + } + } elseif ($values) { + # begin value param set + $updatedPolicyObject = New-Object System.Collections.ArrayList + # Add each value into the object to set the policy + foreach ($value in $values) { + $updatedPolicyObject.add($value) | Out-Null + } + # If only one or a few of the config fields were set, add the remaining items from $foundPolicy.values + $foundPolicy.values | ForEach-Object { + if ($_.configFieldID -notin $updatedPolicyObject.configFieldID) { + $updatedPolicyObject.Add($_) | Out-Null } - # If only one or a few of the config fields were set, add the remaining items from $foundPolicy.values - $foundPolicy.values | ForEach-Object { - if ($_.configFieldID -notin $updatedPolicyObject.configFieldID) { - $updatedPolicyObject.Add($_) | Out-Null + } + } else { + if (($templateObject.objectMap).count -gt 0) { + # Begin user prompt + $initialUserInput = Show-JCPolicyValues -policyObject $templateObject.objectMap -policyValues $foundPolicy.values + # User selects edit all fields + if ($initialUserInput.fieldSelection -eq 'A') { + for ($i = 0; $i -le $initialUserInput.fieldCount; $i++) { + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $i -policyValues $foundPolicy.values } + # Display policy values + # Show-JCPolicyValues -policyObject $updatedPolicyObject -ShowTable $true } - } else { - if (($templateObject.objectMap).count -gt 0) { - # Begin user prompt - $initialUserInput = Show-JCPolicyValues -policyObject $templateObject.objectMap -policyValues $foundPolicy.values - # User selects edit all fields - if ($initialUserInput.fieldSelection -eq 'A') { - for ($i = 0; $i -le $initialUserInput.fieldCount; $i++) { - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $i -policyValues $foundPolicy.values - } - # Display policy values - # Show-JCPolicyValues -policyObject $updatedPolicyObject -ShowTable $true - } - # User selects edit individual field - elseif ($initialUserInput.fieldSelection -ne 'C' -or $initialUserInput.fieldSelection -ne 'A') { - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $initialUserInput.fieldSelection -policyValues $foundPolicy.values - # For set-jcpolicy, add the help & label options - $updatedPolicyObject | ForEach-Object { - if ($_.configFieldID -in $templateObject.objectMap.configFieldID) { - $_ | Add-Member -MemberType NoteProperty -Name "help" -Value $templateObject.objectMap[$templateObject.objectMap.configFieldID.IndexOf($($_.configFieldID))].help - $_ | Add-Member -MemberType NoteProperty -Name "label" -Value $templateObject.objectMap[$templateObject.objectMap.configFieldID.IndexOf($($_.configFieldID))].label - } + # User selects edit individual field + elseif ($initialUserInput.fieldSelection -ne 'C' -or $initialUserInput.fieldSelection -ne 'A') { + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $initialUserInput.fieldSelection -policyValues $foundPolicy.values + # For set-jcpolicy, add the help & label options + $updatedPolicyObject | ForEach-Object { + if ($_.configFieldID -in $templateObject.objectMap.configFieldID) { + $_ | Add-Member -MemberType NoteProperty -Name "help" -Value $templateObject.objectMap[$templateObject.objectMap.configFieldID.IndexOf($($_.configFieldID))].help + $_ | Add-Member -MemberType NoteProperty -Name "label" -Value $templateObject.objectMap[$templateObject.objectMap.configFieldID.IndexOf($($_.configFieldID))].label } - Do { - # Hide option to edit all fields - $userInput = Show-JCPolicyValues -policyObject $updatedPolicyObject -HideAll $true -policyValues $foundPolicy.values - $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $userInput.fieldSelection -policyValues $foundPolicy.values - } while ($userInput.fieldSelection -ne 'C') } + Do { + # Hide option to edit all fields + $userInput = Show-JCPolicyValues -policyObject $updatedPolicyObject -HideAll $true -policyValues $foundPolicy.values + $updatedPolicyObject = Set-JCPolicyConfigField -templateObject $templateObject.objectMap -fieldIndex $userInput.fieldSelection -policyValues $foundPolicy.values + } while ($userInput.fieldSelection -ne 'C') } } - if ($updatedPolicyObject) { - $body = [PSCustomObject]@{ - name = $policyNameFromProcess - template = @{id = $foundPolicy.Template.Id } - values = @($updatedPolicyObject) - } | ConvertTo-Json -Depth 99 - } else { - $body = [PSCustomObject]@{ - name = $policyNameFromProcess - template = @{id = $foundPolicy.Template.Id } - } | ConvertTo-Json -Depth 99 - } - $headers = @{ - 'x-api-key' = $env:JCApiKey - 'x-org-id' = $env:JCOrgId - 'content-type' = "application/json" - } - $response = Invoke-RestMethod -Uri "https://console.jumpcloud.com/api/v2/policies/$($foundPolicy.id)" -Method PUT -Headers $headers -ContentType 'application/json' -Body $body - if ($response) { - $response | Add-Member -MemberType NoteProperty -Name "templateID" -Value $response.template.id - } } - end { - return $response | Select-Object -Property "name", "id", "templateID", "values", "template" + if ($updatedPolicyObject) { + $body = [PSCustomObject]@{ + name = $policyNameFromProcess + template = @{id = $foundPolicy.Template.Id } + values = @($updatedPolicyObject) + } | ConvertTo-Json -Depth 99 + } else { + $body = [PSCustomObject]@{ + name = $policyNameFromProcess + template = @{id = $foundPolicy.Template.Id } + } | ConvertTo-Json -Depth 99 } + $headers = @{ + 'x-api-key' = $env:JCApiKey + 'x-org-id' = $env:JCOrgId + 'content-type' = "application/json" + } + $response = Invoke-RestMethod -Uri "https://console.jumpcloud.com/api/v2/policies/$($foundPolicy.id)" -Method PUT -Headers $headers -ContentType 'application/json' -Body $body + if ($response) { + $response | Add-Member -MemberType NoteProperty -Name "templateID" -Value $response.template.id + } + } + end { + return $response | Select-Object -Property "name", "id", "templateID", "values", "template" } } From b946c8f454d6dced53bcb9d8f84a9906fb1670c9 Mon Sep 17 00:00:00 2001 From: TheJumpCloud Date: Tue, 1 Aug 2023 16:18:55 +0000 Subject: [PATCH 75/77] Updating PowerShell Module;[skip ci] --- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- PowerShell/JumpCloud Module/JumpCloud.psd1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerShell/JumpCloud Module/JumpCloud.nuspec b/PowerShell/JumpCloud Module/JumpCloud.nuspec index 430feefe0..83520d9ef 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.7.0.9314-202307312021 + 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 d2085dc66..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: 7/31/2023 +# Generated on: 8/1/2023 # @{ From bb0aa586284add58bb04c7eaad57eac50f190b05 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Tue, 1 Aug 2023 12:01:49 -0600 Subject: [PATCH 76/77] fix dynamicparam block --- .../Public/Policies/Set-JCPolicy.ps1 | 142 +++++++++--------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 index b51b764ac..f517e7f2f 100644 --- a/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 +++ b/PowerShell/JumpCloud Module/Public/Policies/Set-JCPolicy.ps1 @@ -51,83 +51,83 @@ function Set-JCPolicy { 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"])) { - # Set the policy template object based on policy - $templateObject = Get-JCPolicyTemplateConfigField -templateID $foundPolicy.Template.Id - $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary - # Foreach key in the supplied config file: - foreach ($key in $templateObject.objectMap) { - # Set the dynamic parameters' name - $ParamName_Filter = "$($key.configFieldName)" - # Create the collection of attributes - $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] - # If ValidateSet is specified in the config file, set the value here: - # If the type of value is a bool, create a custom validateSet attribute here: - $paramType = $($key.type) - switch ($paramType) { - 'boolean' { - $arrSet = @("true", "false") - $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) - $AttributeCollection.Add($ValidateSetAttribute) - } - 'multi' { - $paramType = 'string' - $arrSet = $key.validation.values - $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) - $AttributeCollection.Add($ValidateSetAttribute) - } - 'file' { - $paramType = 'string' - } - 'listbox' { - $paramType = [system.string[]] - } - 'table' { - $paramType = [system.object[]] - } - 'exclude' { - Continue - } - Default { - $paramType = 'string' - } + } + # If policy is identified, get the dynamic policy set + if ($foundPolicy.id -And ($PSBoundParameters["PolicyName"] -OR $PSBoundParameters["PolicyID"])) { + # Set the policy template object based on policy + $templateObject = Get-JCPolicyTemplateConfigField -templateID $foundPolicy.Template.Id + $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary + # Foreach key in the supplied config file: + foreach ($key in $templateObject.objectMap) { + # Set the dynamic parameters' name + $ParamName_Filter = "$($key.configFieldName)" + # Create the collection of attributes + $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] + # If ValidateSet is specified in the config file, set the value here: + # If the type of value is a bool, create a custom validateSet attribute here: + $paramType = $($key.type) + switch ($paramType) { + 'boolean' { + $arrSet = @("true", "false") + $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) + $AttributeCollection.Add($ValidateSetAttribute) } - # Set the help message - if ([String]::isNullorEmpty($($key.help))) { - $ParameterAttribute.HelpMessage = "sets the value for the $($key.name) field" - } else { - $ParameterAttribute.HelpMessage = "$($key.help)" + 'multi' { + $paramType = 'string' + $arrSet = $key.validation.values + $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) + $AttributeCollection.Add($ValidateSetAttribute) + } + 'file' { + $paramType = 'string' + } + 'listbox' { + $paramType = [system.string[]] } - # Add the attributes to the attributes collection - $AttributeCollection.Add($ParameterAttribute) - # 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) + 'table' { + $paramType = [system.object[]] } - 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) + 'exclude' { + Continue } + Default { + $paramType = 'string' + } + } + # Set the help message + if ([String]::isNullorEmpty($($key.help))) { + $ParameterAttribute.HelpMessage = "sets the value for the $($key.name) field" + } else { + $ParameterAttribute.HelpMessage = "$($key.help)" + } + # Add the attributes to the attributes collection + $AttributeCollection.Add($ParameterAttribute) + # 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 } + # Returns the dictionary + return $RuntimeParameterDictionary } } begin { From 7d43b06d8d2236269ee73003ecf92e6a19c8993e Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Tue, 1 Aug 2023 14:30:53 -0600 Subject: [PATCH 77/77] fix date --- PowerShell/ModuleChangelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/ModuleChangelog.md b/PowerShell/ModuleChangelog.md index 8648ae7cf..3666c586a 100644 --- a/PowerShell/ModuleChangelog.md +++ b/PowerShell/ModuleChangelog.md @@ -1,6 +1,6 @@ ## 2.7.0 -Release Date: June 30, 2023 +Release Date: August 1, 2023 #### RELEASE NOTES