Skip to content

Commit

Permalink
Merge pull request #505 from TheJumpCloud/JumpCloudModule_2.7.0
Browse files Browse the repository at this point in the history
JumpCloud PowerShell Module v2.7.0
  • Loading branch information
gweinjc authored Aug 1, 2023
2 parents 5898cd0 + 7d43b06 commit 5b115d8
Show file tree
Hide file tree
Showing 18 changed files with 437 additions and 97 deletions.
4 changes: 2 additions & 2 deletions .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion PowerShell/JumpCloud Module/Docs/JumpCloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module Name: JumpCloud
Module Guid: 31c023d1-a901-48c4-90a3-082f91b31646
Download Help Link: https://github.com/TheJumpCloud/support/wiki
Help Version: 2.6.0
Help Version: 2.7.0
Locale: en-US
---

Expand Down
8 changes: 8 additions & 0 deletions PowerShell/JumpCloud Module/Docs/New-JCPolicy.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ PS C:\> New-JCPolicy -TemplateName darwin_Login_Window_Text -Values $policyValu

This would create a new macOS Login Window Text policy with the login window text set to `Welcome to JumpCloud` with the `macOS - Login Window Policy` name. The policy values are set using the `values` parameter. Objects passed into the `values` parameter set must contain the `value` for the policy config field and a `configFieldID`. To get a policy value object, search for any existing policy using `Get-JCPolicy` the `values` object returned from that cmdlet will contain the config fields required to build new policies or edit existing ones.

### Example 5

```PowerShell
PS C:\> New-JCPolicy -TemplateName windows_Advanced:_Custom_Registry_Keys -Name "Windows - Imported Custom Registry Settings" -RegistryFile "/path/to/registryFile.reg"
```

This command would create a new Windows Custom Registry Policy named "Windows - Imported Custom Registry Settings" and populate the values from a registry file. .Reg registry files can be passed into New-JCPolicy as long as the TemplateName is specified with the corresponding "windows_Advanced:\_Custom_Registry_Keys" template. .Reg files will be converted and uploaded to the JumpCloud policy as long as they contain "DWORD", "EXPAND_SZ", "MULTI_SZ", "SZ" or "QWORD" type data.

## PARAMETERS

### -Name
Expand Down
16 changes: 16 additions & 0 deletions PowerShell/JumpCloud Module/Docs/Set-JCPolicy.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ PS C:\> Set-JCPolicy -PolicyName "macOS - Login Window Policy" -Values $policyV

This would update the policy named `macOS - Login Window Policy` with the login window text set to `Welcome to JumpCloud`. The policy values are set using the `values` parameter. Objects passed into the `values` parameter set must contain the `value` for the policy config field and a `configFieldID`. To get a policy value object, search for any existing policy using `Get-JCPolicy` the `values` object returned from that cmdlet will contain the config fields required to build new policies or edit existing ones.

### Example 5

```powershell
PS C:\> Set-JCPolicy -PolicyName "Windows - Imported Custom Registry Settings" -RegistryFile "/path/to/registryFile.reg"
```

This command would append the registry policy's existing values with the imported set of .Reg keys specified by the "RegistryFile" parameter. .Reg files will be converted and uploaded to the JumpCloud policy as long as they contain "DWORD", "EXPAND_SZ", "MULTI_SZ", "SZ" or "QWORD" type data.

### Example 6

```powershell
PS C:\> Set-JCPolicy -PolicyName "Windows - Imported Custom Registry Settings" -RegistryFile "/path/to/registryFile.reg" -RegistryOverwrite
```

This command would overwrite the registry policy's existing values with the imported set of .Reg keys specified by the "RegistryFile" parameter. .Reg files will be converted and uploaded to the JumpCloud policy as long as they contain "DWORD", "EXPAND_SZ", "MULTI_SZ", "SZ" or "QWORD" type data.

## PARAMETERS

### -NewName
Expand Down
2 changes: 1 addition & 1 deletion PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Updates the JumpCloud Module Settings File
## SYNTAX

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

## DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion PowerShell/JumpCloud Module/JumpCloud.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>JumpCloud</id>
<version>2.6.0</version>
<version>2.7.0.9326-202308011615</version>
<description>PowerShell functions to manage a JumpCloud Directory-as-a-Service</description>
<authors>JumpCloud Solutions Architect Team</authors>
<owners>JumpCloud</owners>
Expand Down
4 changes: 2 additions & 2 deletions PowerShell/JumpCloud Module/JumpCloud.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: JumpCloud Solutions Architect Team
#
# Generated on: 6/21/2023
# Generated on: 8/1/2023
#

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

# Version number of this module.
ModuleVersion = '2.6.0'
ModuleVersion = '2.7.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -170,15 +170,24 @@ Function Get-JCResults {
else {
if ($totalCountHeader) {
# Add results to results list
$content = $response.Content
[void]$resultsArray.Add($content)
$content = $response.Content | ConvertFrom-Json
# Check to see size of content
if ($content.Count -le 1) {
[void]$resultsArray.Add($content)
} else {
[void]$resultsArray.AddRange($content)
}
} else {
# Add results to results list
$content = $response.Content | ConvertFrom-Json
if ($null -eq $content.results) {
[void]$resultsArray.Add($content)
} else {
[void]$resultsArray.AddRange($content.results)
if ($($content.results).Count -le 1) {
[void]$resultsArray.Add($content.results)
} else {
[void]$resultsArray.AddRange($content.results)
}
}
}

Expand Down Expand Up @@ -220,25 +229,30 @@ Function Get-JCResults {
# Add results to results list
if ($totalCountHeader) {
# Add results to results list
$content = $response.Content
[void]$resultsArray.Add($content)
Write-Debug ("Page: $($i+1) Amount: " + ($content | ConvertFrom-Json).Count)
$content = $response.Content | ConvertFrom-Json
if ($content.Count -le 1) {
[void]$resultsArray.Add($content)
} else {
[void]$resultsArray.AddRange($content)
}
} else {
# Add results to results list
$content = $response.Content | ConvertFrom-Json
if ($null -eq $content.results) {
[void]$resultsArray.Add($content)
Write-Debug ("Page: $($i+1) Amount: " + ($content | ConvertFrom-Json).Count)
} else {
[void]$resultsArray.AddRange($content.results)
Write-Debug ("Page: $($i+1) Amount: " + ($content.results).Count)
if ($($content.results).Count -le 1) {
[void]$resultsArray.Add($content.results)
} else {
[void]$resultsArray.AddRange($content.results)
}
}
}
}
}
}
end {
if ($totalCountHeader) {
if ($parallel -and $totalCountHeader) {
$resultsArray = $resultsArray | ConvertFrom-Json
}
# Return complete results
Expand Down
107 changes: 107 additions & 0 deletions PowerShell/JumpCloud Module/Private/Policies/Convert-RegToPSObject.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
function Convert-RegToPSObject {
param(
[Parameter(Mandatory = $true)]
[ValidateScript({
if (-Not ($_ | Test-Path) ) {
throw "File or folder does not exist"
}
if (-Not ($_ | Test-Path -PathType Leaf) ) {
throw "The Path argument must be a file. Folder paths are not allowed."
}
if ($_ -notmatch "(\.reg)") {
throw "The file specified in the path argument must be of type reg"
}
return $true
})]
[System.IO.FileInfo]$regFilePath
)
begin {
$regKeys = [System.Collections.ArrayList]@()
[string]$text = $null
$regContent = Get-Content $RegFilePath | Where-Object { ![string]::IsNullOrWhiteSpace($_) } | ForEach-Object { $_.Trim() }
$joinedlines = @()
for ($i = 0; $i -lt $regContent.count; $i++) {
if ($regContent[$i].EndsWith("\")) {
$text = $text + ($regContent[$i] -replace "\\").trim()
} else {
$joinedlines += $text + $regContent[$i]
[string]$text = $null
}
}
}
process {
foreach ($line in $joinedlines) {
# Extract the registry path
if ($line.StartsWith("[")) {
# Throw error if registry is no HKEY_LOCAL_MACHINE
if ($line -notmatch "HKEY_LOCAL_MACHINE") {
throw "JumpCloud Policies only support HKEY_LOCAL_MACHINE/HKLM registry keys"
} else {
$path = $line.TrimStart("[").TrimEnd("]").Replace("HKEY_LOCAL_MACHINE", "").Replace("\\\\", "\\").TrimStart('\')
}
} else {
# Extract Values
if ($line.Contains("=")) {
$valueObject = $($line.Split("=")).Trim("`"")
$valueName = $($valueObject[0]).Trim()
if ($valueObject[1].StartsWith("dword:")) {
#DWORD
$customRegType = "DWORD"
$customData = [int]"0x$(($valueObject[1]).Substring(6))"
} elseif ($valueObject[1].StartsWith("hex(b):")) {
#QWORD
$customRegType = "QWORD"
$value = ($valueObject[1]).Substring(7).split(",")
# Convert to value
$value = for ($i = $value.count - 1; $i -ge 0; $i--) {
$value[$i]
}
$hexValue = '0x' + ($value -join "").trimstart('0')
$customData = [int]$hexValue
} elseif ($valueObject[1].StartsWith("hex(7):")) {
#MULTI_SZ
$customRegType = "multiString"
$value = ($valueObject[1]).Replace("hex(7):", "").split(",")
$value = for ($i = 0; $i -lt $value.count; $i += 2) {
if ($value[$i] -ne '00') {
[string][char][int]('0x' + $value[$i])
} else {
"\0"
}
}
$customData = $value -join ""
} elseif ($valueObject[1].StartsWith("hex(2):")) {
#EXPAND_SZ
$customRegType = "expandString"
$value = ($valueObject[1]).Substring(7).split(",")
$value = for ($i = 0; $i -lt $value.count; $i += 2) {
if ($value[$i] -ne '00') {
[string][char][int]('0x' + $value[$i])
}
}
$customData = $value -join ""
} else {
#STRING
$customRegType = "String"
$customData = $($valueObject[1]).Trim("`"")
}

# Create PSCustomObject for endpoint
$regKey = [PSCustomObject]@{
'customLocation' = $path
'customValueName' = $valueName
'customRegType' = $customRegType
'customData' = $customData
}

# Add object to ArrayList
$regKeys.Add($regKey) | Out-Null
}
}
}
}
end {
# Return objectarray containing keys
return , $regKeys
}
}
20 changes: 20 additions & 0 deletions PowerShell/JumpCloud Module/Public/Policies/New-JCPolicy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ function New-JCPolicy {
# Add the param
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParamName_Filter, $paramType, $AttributeCollection)
$RuntimeParameterDictionary.Add($ParamName_Filter, $RuntimeParameter)
if ($ParamName_Filter -eq "customRegTable") {
$RegImport_RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
$RegImport_AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
$RegImport_ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
$RegImport_paramType = [System.IO.FileInfo]
$RegImport_ParameterAttribute.HelpMessage = 'A .reg file path that will be uploaded into the "Advanced: Custom Registry Keys" Windows Policy template.'
$RegImport_AttributeCollection.Add($RegImport_ParameterAttribute)
$RegImport_RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter('RegistryFile', $RegImport_paramType, $RegImport_AttributeCollection)
$RuntimeParameterDictionary.Add('RegistryFile', $RegImport_RuntimeParameter)
}
}
# Returns the dictionary
return $RuntimeParameterDictionary
Expand Down Expand Up @@ -204,6 +214,15 @@ function New-JCPolicy {
}
}
$newObject.Add($templateObject.objectMap[$i]) | Out-Null
} elseif ('RegistryFile' -in $params.Keys) {
try {
$regKeys = Convert-RegToPSObject -regFilePath $($params.'RegistryFile')
} catch {
throw $_
}
# Set the registryFile as the customRegTable
$templateObject.objectMap[0].value = $regKeys
$newObject.Add($templateObject.objectMap[0]) | Out-Null
} else {
# Else if the dynamicParam for a config field is not specified, set the value from the defaultValue
$templateObject.objectMap[$i].value = $templateObject.objectMap[$i].defaultValue
Expand Down Expand Up @@ -258,6 +277,7 @@ function New-JCPolicy {
} | ConvertTo-Json -Depth 99

}

$headers = @{
'x-api-key' = $env:JCApiKey
'x-org-id' = $env:JCOrgId
Expand Down
Loading

0 comments on commit 5b115d8

Please sign in to comment.