Skip to content

Commit

Permalink
Merge pull request #381 from TheJumpCloud/JumpCloudModule_1.22.0
Browse files Browse the repository at this point in the history
JumpCloud module 1.22.0
  • Loading branch information
kmaranionjc authored May 17, 2022
2 parents 63e4fff + 32add55 commit d094d38
Show file tree
Hide file tree
Showing 15 changed files with 372 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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: 1.21.0
Help Version: 1.22.0
Locale: en-US
---

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: 5/10/2022
# Generated on: 5/17/2022
#

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

# Version number of this module.
ModuleVersion = '1.21.0'
ModuleVersion = '1.22.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ Function Get-JCResults
{
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true, HelpMessage = 'URL of Endpoint')][ValidateNotNullOrEmpty()]$URL
[Parameter(Mandatory = $true, HelpMessage = 'URL of Endpoint')][ValidateNotNullOrEmpty()]$URL,
[Parameter(Mandatory = $true, HelpMessage = 'Method of WebRequest')][ValidateNotNullOrEmpty()]$method,
[Parameter(Mandatory = $true, HelpMessage = 'Limit of WebRequest')][ValidateNotNullOrEmpty()]$limit,
[Parameter(Mandatory = $false, HelpMessage = 'Body of WebRequest, if required')]$body
)
begin {
$hdrs = @{
Expand All @@ -16,7 +19,7 @@ Function Get-JCResults
}
$resultsArray = @()
$totalCount = 1
$limit = 100
$limit = [int]$limit
$skip = 0
}
process {
Expand All @@ -29,11 +32,16 @@ Function Get-JCResults
$passCounter = [math]::ceiling($totalCount/$limit)
Write-Debug "number of passes: $passCounter"
$resultsArray += $response.Content | ConvertFrom-Json

for($i = 1; $i -lt $passCounter; $i++) {
$skip += $limit
$limitURL = $URL + "?limit=$limit&skip=$skip"
$response = Invoke-WebRequest -Method GET -Uri $limitURL -Headers $hdrs -UserAgent:(Get-JCUserAgent)
if ($body){
$response = Invoke-WebRequest -Method $method -Body $body -Uri $limitURL -Headers $hdrs -UserAgent:(Get-JCUserAgent)
}
else {
$response = Invoke-WebRequest -Method $method -Uri $limitURL -Headers $hdrs -UserAgent:(Get-JCUserAgent)
}
$resultsArray += $response.Content | ConvertFrom-Json
Write-Debug ("Pass: $i Amount: " + ($response.Content | ConvertFrom-Json).Count)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Function Get-JCSystemGroupMember ()
Write-Debug "$Group_ID"

$limitURL = "{0}/api/v2/Systemgroups/{1}/members" -f $JCUrlBasePath, $Group_ID
$rawResults = Get-JCResults -Url $limitURL
$rawResults = Get-JCResults -Url $limitURL -method "GET" -limit 100

foreach ($uid in $rawResults)
{
Expand Down Expand Up @@ -86,7 +86,7 @@ Function Get-JCSystemGroupMember ()

{
$limitURL = "{0}/api/v2/Systemgroups/{1}/members" -f $JCUrlBasePath, $ByID
$resultsArray = Get-JCResults -Url $limitURL
$resultsArray = Get-JCResults -Url $limitURL -method "GET" -limit 100

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Function Get-JCUserGroupMember ()

$limitURL = "{0}/api/v2/usergroups/{1}/members" -f $JCUrlBasePath, $Group_ID
Write-Debug $limitURL
$rawResults = Get-JCResults -Url $limitURL
$rawResults = Get-JCResults -Url $limitURL -method "GET" -limit 100

foreach ($uid in $rawResults)
{
Expand Down Expand Up @@ -82,7 +82,7 @@ Function Get-JCUserGroupMember ()
{
$limitURL = "{0}/api/v2/usergroups/{1}/members" -f $JCUrlBasePath, $ByID
Write-Debug $limitURL
$resultsArray = Get-JCResults -Url $limitURL
$resultsArray = Get-JCResults -Url $limitURL -method "GET" -limit 100

}
}
Expand Down
52 changes: 37 additions & 15 deletions PowerShell/JumpCloud Module/Public/Users/Get-JCUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Function Get-JCUser ()
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'SearchFilter', HelpMessage = 'The managedAppleId of the JumpCloud user you wish to search for.')]
[String]$managedAppleId,

[Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'SearchFilter', HelpMessage = 'The manager username or ID of the JumpCloud user you wish to search for.')]
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'SearchFilter', HelpMessage = 'The manager username, primary email or ID of the JumpCloud user you wish to search for.')]
[String]$manager,

[Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'SearchFilter', HelpMessage = 'A search filter to return users that are in an ACTIVATED, STAGED or SUSPENDED state')]
Expand Down Expand Up @@ -314,36 +314,58 @@ Function Get-JCUser ()
if (((Select-String -InputObject $param.Value -Pattern $regexPattern).Matches.value)::IsNullOrEmpty){
# if we have a 24 characterid, try to match the id using the search endpoint
$managerSearch = @{
filter = @{
or = @(
'_id:$eq:' + $param.Value
)
searchFilter = @{
searchTerm = @($param.Value)
fields = @('id')
}
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
# Set managerValue; this is a validated user id
$managerValue = $managerResults.id
# if no value was returned, then assume the case this is actually a username and search
# if no value was returned, then assume the case this is actually a username and search
if (!$managerValue){
$managerSearch = @{
filter = @{
or = @(
'username:$eq:' + $param.Value
)
searchFilter = @{
searchTerm = @($param.Value)
fields = @('username')
}
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
# Set managerValue from the matched username
$managerValue = $managerResults.id
}
}
else {
# Use class mailaddress to check if $param.value is email
try {
$null = [mailaddress]$EmailAddress
# Search manager using email
$managerSearch = @{
searchFilter = @{
searchTerm = @($param.Value)
fields = @('email')
}
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
# Set managerValue; this is a validated user id
$managerValue = $managerResults.id
if (!$managerValue){
$managerSearch = @{
searchFilter = @{
searchTerm = @($param.Value)
fields = @('username')
}
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
# Set managerValue from the matched username
$managerValue = $managerResults.id
}
}
catch {
# search the username in the search endpoint
$managerSearch = @{
filter = @{
or = @(
'username:$eq:' + $param.Value
)
searchFilter = @{
searchTerm = @($param.Value)
fields = @('username')
}
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
Expand Down
50 changes: 36 additions & 14 deletions PowerShell/JumpCloud Module/Public/Users/New-JCUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Function New-JCUser ()
[string]
$state,

[Parameter(ValueFromPipelineByPropertyName = $True, HelpMessage = 'The manager username or ID of the JumpCloud manager user; must be a valid user')]
[Parameter(ValueFromPipelineByPropertyName = $True, HelpMessage = 'The manager username, ID or primary email of the JumpCloud manager user; must be a valid user')]
[string]$manager,

[Parameter(ValueFromPipelineByPropertyName = $True, HelpMessage = 'The managedAppleId for the user')]
Expand Down Expand Up @@ -326,10 +326,9 @@ Function New-JCUser ()
if (((Select-String -InputObject $param.Value -Pattern $regexPattern).Matches.value)::IsNullOrEmpty){
# if we have a 24 characterid, try to match the id using the search endpoint
$managerSearch = @{
filter = @{
or = @(
'_id:$eq:' + $param.Value
)
searchFilter = @{
searchTerm = @($param.Value)
fields = @('id')
}
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
Expand All @@ -338,24 +337,47 @@ Function New-JCUser ()
# if no value was returned, then assume the case this is actuallty a username and search
if (!$managerValue){
$managerSearch = @{
filter = @{
or = @(
'username:$eq:' + $param.Value
)
searchFilter = @{
searchTerm = @($param.Value)
fields = @('username')
}
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
# Set managerValue from the matched username
$managerValue = $managerResults.id
}
}
else {
# Use class mailaddress to check if $param.value is email
try {
$null = [mailaddress]$EmailAddress
$managerSearch = @{
searchFilter = @{
searchTerm = @($param.Value)
fields = @('email')
}
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
# Set managerValue; this is a validated user id
$managerValue = $managerResults.id
# if no value was returned, then assume the case this is actuallty a username and search
if (!$managerValue){
$managerSearch = @{
searchFilter = @{
searchTerm = @($param.Value)
fields = @('username')
}
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
# Set managerValue from the matched username
$managerValue = $managerResults.id
}
}
catch {
# search the username in the search endpoint
$managerSearch = @{
filter = @{
or = @(
'username:$eq:' + $param.Value
)
searchFilter = @{
searchTerm = @($param.Value)
fields = @('username')
}
}
$managerResults = Search-JcSdkUser -Body:($managerSearch)
Expand Down
Loading

0 comments on commit d094d38

Please sign in to comment.