diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index e534beacc..04fdc3070 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,9 +1,11 @@ # Support Code Owners -# PowerShell Module +- @TheJumpCloud/customer-tools + +## PowerShell Module & Command Gallery /PowerShell/ @TheJumpCloud/customer-tools -# Scripts +## Scripts /scripts/ @TheJumpCloud/customer-tools diff --git a/.github/workflows/powershell-module-ci.yml b/.github/workflows/powershell-module-ci.yml index 454f41777..ce91fda1d 100644 --- a/.github/workflows/powershell-module-ci.yml +++ b/.github/workflows/powershell-module-ci.yml @@ -99,6 +99,7 @@ jobs: 'JumpCloud.SDK.V1' = @{Repository = 'PSGallery'; RequiredVersion = 'latest'} 'JumpCloud.SDK.V2' = @{Repository = 'PSGallery'; RequiredVersion = 'latest'} 'JumpCloud.SDK.DirectoryInsights' = @{Repository = 'PSGallery'; RequiredVersion = 'latest'} + 'powershell-yaml' = @{Repository = 'PSGallery'; RequiredVersion = '0.4.7'} } foreach ($RequiredModule in $PSDependencies.Keys) { diff --git a/PowerShell/JumpCloud Module/JumpCloud.psd1 b/PowerShell/JumpCloud Module/JumpCloud.psd1 index fe072a986..6ab67f3f2 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.psd1 +++ b/PowerShell/JumpCloud Module/JumpCloud.psd1 @@ -3,160 +3,160 @@ # # Generated by: JumpCloud Solutions Architect Team # -# Generated on: 1/17/2024 +# Generated on: 4/02/2024 # @{ -# Script module or binary module file associated with this manifest. -RootModule = 'JumpCloud.psm1' - -# Version number of this module. -ModuleVersion = '2.10.0' + # Script module or binary module file associated with this manifest. + RootModule = 'JumpCloud.psm1' + + # Version number of this module. + ModuleVersion = '2.10.1' -# Supported PSEditions -# CompatiblePSEditions = @() + # Supported PSEditions + # CompatiblePSEditions = @() -# ID used to uniquely identify this module -GUID = '31c023d1-a901-48c4-90a3-082f91b31646' + # ID used to uniquely identify this module + GUID = '31c023d1-a901-48c4-90a3-082f91b31646' -# Author of this module -Author = 'JumpCloud Solutions Architect Team' + # Author of this module + Author = 'JumpCloud Solutions Architect Team' -# Company or vendor of this module -CompanyName = 'JumpCloud' + # Company or vendor of this module + CompanyName = 'JumpCloud' -# Copyright statement for this module -Copyright = '(c) JumpCloud. All rights reserved.' + # Copyright statement for this module + Copyright = '(c) JumpCloud. All rights reserved.' -# Description of the functionality provided by this module -Description = 'PowerShell functions to manage a JumpCloud Directory-as-a-Service' + # Description of the functionality provided by this module + Description = 'PowerShell functions to manage a JumpCloud Directory-as-a-Service' -# Minimum version of the PowerShell engine required by this module -PowerShellVersion = '4.0' + # Minimum version of the PowerShell engine required by this module + PowerShellVersion = '4.0' -# Name of the PowerShell host required by this module -# PowerShellHostName = '' + # Name of the PowerShell host required by this module + # PowerShellHostName = '' -# Minimum version of the PowerShell host required by this module -# PowerShellHostVersion = '' + # Minimum version of the PowerShell host required by this module + # PowerShellHostVersion = '' -# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# DotNetFrameworkVersion = '' + # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # DotNetFrameworkVersion = '' -# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# ClrVersion = '' + # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # ClrVersion = '' -# Processor architecture (None, X86, Amd64) required by this module -# ProcessorArchitecture = '' + # Processor architecture (None, X86, Amd64) required by this module + # ProcessorArchitecture = '' -# Modules that must be imported into the global environment prior to importing this module -RequiredModules = @('JumpCloud.SDK.DirectoryInsights', - 'JumpCloud.SDK.V1', - 'JumpCloud.SDK.V2') + # Modules that must be imported into the global environment prior to importing this module + RequiredModules = @('JumpCloud.SDK.DirectoryInsights', + 'JumpCloud.SDK.V1', + 'JumpCloud.SDK.V2') -# Assemblies that must be loaded prior to importing this module -# RequiredAssemblies = @() + # Assemblies that must be loaded prior to importing this module + # RequiredAssemblies = @() -# Script files (.ps1) that are run in the caller's environment prior to importing this module. -# ScriptsToProcess = @() + # Script files (.ps1) that are run in the caller's environment prior to importing this module. + # ScriptsToProcess = @() -# Type files (.ps1xml) to be loaded when importing this module -# TypesToProcess = @() + # Type files (.ps1xml) to be loaded when importing this module + # TypesToProcess = @() -# Format files (.ps1xml) to be loaded when importing this module -# FormatsToProcess = @() + # Format files (.ps1xml) to be loaded when importing this module + # FormatsToProcess = @() -# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess -# NestedModules = @() + # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess + # NestedModules = @() -# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = 'Add-JCAssociation', 'Add-JCCommandTarget', 'Add-JCGsuiteMember', - 'Add-JCOffice365Member', 'Add-JCRadiusReplyAttribute', - 'Add-JCSystemGroupMember', 'Add-JCSystemUser', - 'Add-JCUserGroupMember', 'Backup-JCOrganization', 'Connect-JCOnline', - 'Copy-JCAssociation', 'Get-JCAssociation', 'Get-JCBackup', - 'Get-JCCloudDirectory', 'Get-JCCommand', 'Get-JCCommandResult', - 'Get-JCCommandTarget', 'Get-JCEvent', 'Get-JCEventCount', 'Get-JCGroup', - 'Get-JCOrganization', 'Get-JCPolicy', 'Get-JCPolicyResult', - 'Get-JCPolicyTargetGroup', 'Get-JCPolicyTargetSystem', - 'Get-JCRadiusReplyAttribute', 'Get-JCRadiusServer', 'Get-JCSystem', - 'Get-JCSystemApp', 'Get-JCSystemGroupMember', 'Get-JCSystemInsights', - 'Get-JCSystemUser', 'Get-JCUser', 'Get-JCUserGroupMember', - 'Import-JCCommand', 'Import-JCMSPFromCSV', 'Import-JCUsersFromCSV', - 'Invoke-JCCommand', 'Invoke-JCDeployment', 'New-JCCommand', - 'New-JCDeploymentTemplate', 'New-JCImportTemplate', - 'New-JCMSPImportTemplate', 'New-JCPolicy', 'New-JCRadiusServer', - 'New-JCSystemGroup', 'New-JCUser', 'New-JCUserGroup', - 'Remove-JCAssociation', 'Remove-JCCommand', 'Remove-JCCommandResult', - 'Remove-JCCommandTarget', 'Remove-JCGsuiteMember', - 'Remove-JCOffice365Member', 'Remove-JCPolicy', - 'Remove-JCRadiusReplyAttribute', 'Remove-JCRadiusServer', - 'Remove-JCSystem', 'Remove-JCSystemGroup', - 'Remove-JCSystemGroupMember', 'Remove-JCSystemUser', 'Remove-JCUser', - 'Remove-JCUserGroup', 'Remove-JCUserGroupMember', - 'Send-JCPasswordReset', 'Set-JCCloudDirectory', 'Set-JCCommand', - 'Set-JCOrganization', 'Set-JCPolicy', 'Set-JCRadiusReplyAttribute', - 'Set-JCRadiusServer', 'Set-JCSettingsFile', 'Set-JCSystem', - 'Set-JCSystemUser', 'Set-JCUser', 'Set-JCUserGroupLDAP', - 'Update-JCModule', 'Update-JCMSPFromCSV', 'Update-JCUsersFromCSV' + # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. + FunctionsToExport = 'Add-JCAssociation', 'Add-JCCommandTarget', 'Add-JCGsuiteMember', + 'Add-JCOffice365Member', 'Add-JCRadiusReplyAttribute', + 'Add-JCSystemGroupMember', 'Add-JCSystemUser', + 'Add-JCUserGroupMember', 'Backup-JCOrganization', 'Connect-JCOnline', + 'Copy-JCAssociation', 'Get-JCAssociation', 'Get-JCBackup', + 'Get-JCCloudDirectory', 'Get-JCCommand', 'Get-JCCommandResult', + 'Get-JCCommandTarget', 'Get-JCEvent', 'Get-JCEventCount', 'Get-JCGroup', + 'Get-JCOrganization', 'Get-JCPolicy', 'Get-JCPolicyResult', + 'Get-JCPolicyTargetGroup', 'Get-JCPolicyTargetSystem', + 'Get-JCRadiusReplyAttribute', 'Get-JCRadiusServer', 'Get-JCSystem', + 'Get-JCSystemApp', 'Get-JCSystemGroupMember', 'Get-JCSystemInsights', + 'Get-JCSystemUser', 'Get-JCUser', 'Get-JCUserGroupMember', + 'Import-JCCommand', 'Import-JCMSPFromCSV', 'Import-JCUsersFromCSV', + 'Invoke-JCCommand', 'Invoke-JCDeployment', 'New-JCCommand', + 'New-JCDeploymentTemplate', 'New-JCImportTemplate', + 'New-JCMSPImportTemplate', 'New-JCPolicy', 'New-JCRadiusServer', + 'New-JCSystemGroup', 'New-JCUser', 'New-JCUserGroup', + 'Remove-JCAssociation', 'Remove-JCCommand', 'Remove-JCCommandResult', + 'Remove-JCCommandTarget', 'Remove-JCGsuiteMember', + 'Remove-JCOffice365Member', 'Remove-JCPolicy', + 'Remove-JCRadiusReplyAttribute', 'Remove-JCRadiusServer', + 'Remove-JCSystem', 'Remove-JCSystemGroup', + 'Remove-JCSystemGroupMember', 'Remove-JCSystemUser', 'Remove-JCUser', + 'Remove-JCUserGroup', 'Remove-JCUserGroupMember', + 'Send-JCPasswordReset', 'Set-JCCloudDirectory', 'Set-JCCommand', + 'Set-JCOrganization', 'Set-JCPolicy', 'Set-JCRadiusReplyAttribute', + 'Set-JCRadiusServer', 'Set-JCSettingsFile', 'Set-JCSystem', + 'Set-JCSystemUser', 'Set-JCUser', 'Set-JCUserGroupLDAP', + 'Update-JCModule', 'Update-JCMSPFromCSV', 'Update-JCUsersFromCSV' -# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. -CmdletsToExport = @() + # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. + CmdletsToExport = @() -# Variables to export from this module -VariablesToExport = '*' + # Variables to export from this module + VariablesToExport = '*' -# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. -AliasesToExport = 'New-JCAssociation' + # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. + AliasesToExport = 'New-JCAssociation' -# DSC resources to export from this module -# DscResourcesToExport = @() + # DSC resources to export from this module + # DscResourcesToExport = @() -# List of all modules packaged with this module -# ModuleList = @() + # List of all modules packaged with this module + # ModuleList = @() -# List of all files packaged with this module -# FileList = @() + # List of all files packaged with this module + # FileList = @() -# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. -PrivateData = @{ + # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. + PrivateData = @{ - PSData = @{ + PSData = @{ - # Tags applied to this module. These help with module discovery in online galleries. - Tags = 'JumpCloud', 'DaaS', 'Jump', 'Cloud', 'Directory' + # Tags applied to this module. These help with module discovery in online galleries. + Tags = 'JumpCloud', 'DaaS', 'Jump', 'Cloud', 'Directory' - # A URL to the license for this module. - LicenseUri = 'https://github.com/TheJumpCloud/support/blob/master/PowerShell/LICENSE' + # A URL to the license for this module. + LicenseUri = 'https://github.com/TheJumpCloud/support/blob/master/PowerShell/LICENSE' - # A URL to the main website for this project. - ProjectUri = 'https://github.com/TheJumpCloud/support/wiki' + # A URL to the main website for this project. + ProjectUri = 'https://github.com/TheJumpCloud/support/wiki' - # A URL to an icon representing this module. - IconUri = 'https://avatars1.githubusercontent.com/u/4927461?s=200&v=4' + # A URL to an icon representing this module. + IconUri = 'https://avatars1.githubusercontent.com/u/4927461?s=200&v=4' - # ReleaseNotes of this module - ReleaseNotes = 'https://git.io/jc-pwsh-releasenotes' + # ReleaseNotes of this module + ReleaseNotes = 'https://git.io/jc-pwsh-releasenotes' - # Prerelease string of this module - # Prerelease = '' + # Prerelease string of this module + # Prerelease = '' - # Flag to indicate whether the module requires explicit user acceptance for install/update/save - # RequireLicenseAcceptance = $false + # Flag to indicate whether the module requires explicit user acceptance for install/update/save + # RequireLicenseAcceptance = $false - # External dependent modules of this module - # ExternalModuleDependencies = @() + # External dependent modules of this module + # ExternalModuleDependencies = @() - } # End of PSData hashtable + } # End of PSData hashtable -} # End of PrivateData hashtable + } # End of PrivateData hashtable -# HelpInfo URI of this module -HelpInfoURI = 'https://github.com/TheJumpCloud/support/wiki' + # HelpInfo URI of this module + HelpInfoURI = 'https://github.com/TheJumpCloud/support/wiki' -# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. -# DefaultCommandPrefix = '' + # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. + # DefaultCommandPrefix = '' } diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCObject.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCObject.ps1 index 480108de6..4ea262ca0 100755 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCObject.ps1 +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCObject.ps1 @@ -209,6 +209,8 @@ Function Get-JCObject { if ($dirResult.Name -eq $SearchByValueItem) { # if match on name, just API results to just be the single match $Result = $dirResult + } elseif ($dirResult.id -eq $SearchByValueItem) { + $Result = $dirResult } else { $result = $result | Where-Object { $_ -ne $dirResult } } diff --git a/PowerShell/JumpCloud Module/Public/Commands/Get-JCCommand.ps1 b/PowerShell/JumpCloud Module/Public/Commands/Get-JCCommand.ps1 index 565f37efa..64832fd22 100644 --- a/PowerShell/JumpCloud Module/Public/Commands/Get-JCCommand.ps1 +++ b/PowerShell/JumpCloud Module/Public/Commands/Get-JCCommand.ps1 @@ -20,8 +20,8 @@ Function Get-JCCommand () { [Parameter( ValueFromPipelineByPropertyName, ParameterSetName = 'SearchFilter', HelpMessage = 'The scheduled command repeat type (minute, hour, day, week, month) of the JumpCloud Command you wish to search for ex. Get-JCCommand -scheduleRepeatType ')] [ValidateSet('minute', 'hour', 'day', 'week', 'month')] [string]$scheduleRepeatType, - [Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'SearchFilter', HelpMessage = 'Allows you to return select properties on JumpCloud commands objects. Specifying what properties are returned can drastically increase the speed of the API call with a large data set. Valid properties that can be returned are: ''command'', ''name'',''launchType'',''commandType'',''trigger'',''scheduleRepeatType''')] - [ValidateSet('command', 'name', 'launchType', 'commandType', 'trigger', 'scheduleRepeatType')] + [Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'SearchFilter', HelpMessage = 'Allows you to return select properties on JumpCloud commands objects. Specifying what properties are returned can drastically increase the speed of the API call with a large data set. Valid properties that can be returned are: ''command'', ''name'',''launchType'',''commandType'',''trigger'',''scheduleRepeatType'',''listensTo'',''organization'',''commandRunners'',''schedule'',''shell'',''timeout'',''sudo'',''template'',''scheduleYear'',''timeToLiveSeconds'',''files'',''user'',''systems''')] + [ValidateSet('command', 'name', 'launchType', 'commandType', 'trigger', 'scheduleRepeatType', 'listensTo', 'organization', 'commandRunners', 'schedule', 'shell', 'timeout', 'sudo', 'template', 'scheduleYear', 'timeToLiveSeconds', 'files', 'user', 'systems')] [String[]]$returnProperties, [Parameter(Mandatory, ValueFromPipelineByPropertyName, diff --git a/PowerShell/JumpCloud Module/Public/Directory/Add-JCGsuiteMember.ps1 b/PowerShell/JumpCloud Module/Public/Directory/Add-JCGsuiteMember.ps1 index 19019b280..83f86bcb8 100644 --- a/PowerShell/JumpCloud Module/Public/Directory/Add-JCGsuiteMember.ps1 +++ b/PowerShell/JumpCloud Module/Public/Directory/Add-JCGsuiteMember.ps1 @@ -55,11 +55,11 @@ function Add-JCGsuiteMember () { throw "Username: $Username was not found." } } - Set-JcSdkGSuiteAssociation -GsuiteId $CloudDirectory.Id -Op 'add' -Type 'user' -Id $UserID -ErrorVariable addError -ErrorAction SilentlyContinue - if ($addError) { - $Status = $addError.ErrorDetails.Message - } else { + try { + Set-JcSdkGSuiteAssociation -GsuiteId $CloudDirectory.Id -Op 'add' -Type 'user' -Id $UserID $Status = 'Added' + } catch { + $Status = $_.Exception.Message } $FormattedResults = [PSCustomObject]@{ @@ -76,11 +76,11 @@ function Add-JCGsuiteMember () { throw "Group does not exist. Run 'Get-JCGroup -type User' to see a list of all your JumpCloud user groups." } } - Set-JcSdkGSuiteAssociation -GsuiteId $CloudDirectory.Id -Op 'add' -Type 'user_group' -Id $GroupID -ErrorVariable addError -ErrorAction SilentlyContinue - if ($addError) { - $Status = $addError.ErrorDetails.Message - } else { + try { + Set-JcSdkGSuiteAssociation -GsuiteId $CloudDirectory.Id -Op 'add' -Type 'user_group' -Id $GroupID $Status = 'Added' + } catch { + $Status = $_.Exception.Message } $FormattedResults = [PSCustomObject]@{ diff --git a/PowerShell/JumpCloud Module/Public/Directory/Add-JCOffice365Member.ps1 b/PowerShell/JumpCloud Module/Public/Directory/Add-JCOffice365Member.ps1 index 22b16a7a3..f024ee632 100644 --- a/PowerShell/JumpCloud Module/Public/Directory/Add-JCOffice365Member.ps1 +++ b/PowerShell/JumpCloud Module/Public/Directory/Add-JCOffice365Member.ps1 @@ -55,11 +55,11 @@ function Add-JCOffice365Member () { throw "Username: $Username was not found." } } - Set-JcSdkOffice365Association -Office365Id $CloudDirectory.Id -Op 'add' -Type 'user' -Id $UserID -ErrorVariable addError -ErrorAction SilentlyContinue - if ($addError) { - $Status = $addError.ErrorDetails.Message - } else { + try { + Set-JcSdkOffice365Association -Office365Id $CloudDirectory.Id -Op 'add' -Type 'user' -Id $UserID $Status = 'Added' + } catch { + $Status = $_.Exception.Message } $FormattedResults = [PSCustomObject]@{ @@ -76,11 +76,11 @@ function Add-JCOffice365Member () { throw "Group does not exist. Run 'Get-JCGroup -type User' to see a list of all your JumpCloud user groups." } } - Set-JcSdkOffice365Association -Office365Id $CloudDirectory.Id -Op 'add' -Type 'user_group' -Id $GroupID -ErrorVariable addError -ErrorAction SilentlyContinue - if ($addError) { - $Status = $addError.ErrorDetails.Message - } else { + try { + Set-JcSdkOffice365Association -Office365Id $CloudDirectory.Id -Op 'add' -Type 'user_group' -Id $GroupID $Status = 'Added' + } catch { + $Status = $_.Exception.Message } $FormattedResults = [PSCustomObject]@{ diff --git a/PowerShell/JumpCloud Module/Public/Directory/Remove-JCGsuiteMember.ps1 b/PowerShell/JumpCloud Module/Public/Directory/Remove-JCGsuiteMember.ps1 index 0a048642a..dd1ca0642 100644 --- a/PowerShell/JumpCloud Module/Public/Directory/Remove-JCGsuiteMember.ps1 +++ b/PowerShell/JumpCloud Module/Public/Directory/Remove-JCGsuiteMember.ps1 @@ -55,11 +55,11 @@ function Remove-JCGsuiteMember () { throw "Username: $Username was not found." } } - Set-JcSdkGSuiteAssociation -GsuiteId $CloudDirectory.Id -Op 'remove' -Type 'user' -Id $UserID -ErrorVariable removeError -ErrorAction SilentlyContinue - if ($removeError) { - $Status = $removeError.ErrorDetails.Message - } else { + try { + Set-JcSdkGSuiteAssociation -GsuiteId $CloudDirectory.Id -Op 'remove' -Type 'user' -Id $UserID $Status = 'Removed' + } catch { + $Status = $_.Exception.Message } $FormattedResults = [PSCustomObject]@{ @@ -76,12 +76,13 @@ function Remove-JCGsuiteMember () { throw "Group does not exist. Run 'Get-JCGroup -type User' to see a list of all your JumpCloud user groups." } } - Set-JcSdkGSuiteAssociation -GsuiteId $CloudDirectory.Id -Op 'remove' -Type 'user_group' -Id $GroupID -ErrorVariable removeError -ErrorAction SilentlyContinue - if ($removeError) { - $Status = $removeError.ErrorDetails.Message - } else { + try { + Set-JcSdkGSuiteAssociation -GsuiteId $CloudDirectory.Id -Op 'remove' -Type 'user_group' -Id $GroupID $Status = 'Removed' + } catch { + $Status = $_.Exception.Message } + $FormattedResults = [PSCustomObject]@{ 'DirectoryName' = $CloudDirectory.Name diff --git a/PowerShell/JumpCloud Module/Public/Directory/Remove-JCOffice365Member.ps1 b/PowerShell/JumpCloud Module/Public/Directory/Remove-JCOffice365Member.ps1 index 5e17705f4..940e26d87 100644 --- a/PowerShell/JumpCloud Module/Public/Directory/Remove-JCOffice365Member.ps1 +++ b/PowerShell/JumpCloud Module/Public/Directory/Remove-JCOffice365Member.ps1 @@ -55,11 +55,11 @@ function Remove-JCOffice365Member () { throw "Username: $Username was not found." } } - Set-JcSdkOffice365Association -Office365Id $CloudDirectory.Id -Op 'remove' -Type 'user' -Id $UserID -ErrorVariable removeError -ErrorAction SilentlyContinue - if ($removeError) { - $Status = $removeError.ErrorDetails.Message - } else { + try { + Set-JcSdkOffice365Association -Office365Id $CloudDirectory.Id -Op 'remove' -Type 'user' -Id $UserID $Status = 'Removed' + } catch { + $Status = $_.Exception.Message } $FormattedResults = [PSCustomObject]@{ @@ -76,11 +76,11 @@ function Remove-JCOffice365Member () { throw "Group does not exist. Run 'Get-JCGroup -type User' to see a list of all your JumpCloud user groups." } } - Set-JcSdkOffice365Association -Office365Id $CloudDirectory.Id -Op 'remove' -Type 'user_group' -Id $GroupID -ErrorVariable removeError -ErrorAction SilentlyContinue - if ($removeError) { - $Status = $removeError.ErrorDetails.Message - } else { + try { + Set-JcSdkOffice365Association -Office365Id $CloudDirectory.Id -Op 'remove' -Type 'user_group' -Id $GroupID $Status = 'Removed' + } catch { + $Status = $_.Exception.Message } $FormattedResults = [PSCustomObject]@{ diff --git a/PowerShell/JumpCloud Module/Public/DirectoryInsights/Get-JCEvent.ps1 b/PowerShell/JumpCloud Module/Public/DirectoryInsights/Get-JCEvent.ps1 index 5baf96a59..e6932d360 100644 --- a/PowerShell/JumpCloud Module/Public/DirectoryInsights/Get-JCEvent.ps1 +++ b/PowerShell/JumpCloud Module/Public/DirectoryInsights/Get-JCEvent.ps1 @@ -12,37 +12,13 @@ Query the API for Directory Insights events curl -X POST 'https://api.jumpcloud.com/insights/directory/v1/events' -H 'Content-Type: application/json' -H 'x-api-key: REPLACE_KEY_VALUE' --data '{\"service\": [\"all\"], \"start_time\": \"2021-07-14T23:00:00Z\", \"end_time\": \"2021-07-28T14:00:00Z\", \"sort\": \"DESC\", \"fields\": [\"timestamp\", \"event_type\", \"initiated_by\", \"success\", \"client_ip\", \"provider\", \"organization\"]}' ``` .Example -PS C:\> Get-JCEvent -Service:('all') -StartTime:((Get-date).AddDays(-30)) +PS C:\> {{ Add code here }} -Pull all event records from the last thirty days +{{ Add output here }} .Example -PS C:\> Get-JCEvent -Service:('directory') -StartTime:((Get-date).AddHours(-1)) -Limit:('10') +PS C:\> {{ Add code here }} -Get directory results from the last hour limit to the last 10 results in the time range -.Example -PS C:\> Get-JCEvent -Service:('directory') -StartTime:((Get-date).AddDays(-30)) -Sort:("DESC") -EndTime:((Get-date).AddDays(-5)) - -Get directory results between 30 and 5 days ago, sort timestamp by descending value -.Example -PS C:\> Get-JCEvent -Service:('directory') -StartTime:((Get-date).AddDays(-30)) -Limit:('10') -searchTermAnd:@{"event_type" = "group_create"} - -Get only group_create from the last thirty days -.Example -PS C:\> Get-JCEvent -Service:('all') -StartTime:('2020-04-14T00:00:00Z') -EndTime:('2020-04-20T23:00:00Z') -SearchTermOr @{"initiated_by.username" = @("user.1", "user.2")} - -Get login events initiated by either "user.1" or "user.2" between a universal time zone range -.Example -PS C:\> Get-JCEvent -Service:('all') -StartTime:('2020-04-14T00:00:00Z') -EndTime:('2020-04-20T23:00:00Z') -SearchTermAnd @{"event_type" = "admin_login_attempt"; "resource.email" = "admin.user@adminbizorg.com"} - -Get all events between a date range and match event_type = admin_login_attempt and resource.email = admin.user@adminbizorg.com -.Example -PS C:\> Get-JCEvent -Service:('sso') -StartTime:('2020-04-14T00:00:00Z') -EndTime:('2020-04-20T23:00:00Z') -SearchTermAnd @{"initiated_by.username" = "user.1"} - -Get sso events with the search term initiated_by: username with value "user.1" -.Example -PS C:\> Get-JCEvent -Service:('all') -StartTime:('2020-04-14T00:00:00Z') -EndTime:('2020-04-20T23:00:00Z') -SearchTermAnd @{"event_type" = "organization_update"} - -Get all events filtered by organization_update term between a date range +{{ Add output here }} .Inputs JumpCloud.SDK.DirectoryInsights.Models.IEventQuery diff --git a/PowerShell/JumpCloud Module/Public/DirectoryInsights/Get-JCEventCount.ps1 b/PowerShell/JumpCloud Module/Public/DirectoryInsights/Get-JCEventCount.ps1 index f77690c23..7047b17d7 100644 --- a/PowerShell/JumpCloud Module/Public/DirectoryInsights/Get-JCEventCount.ps1 +++ b/PowerShell/JumpCloud Module/Public/DirectoryInsights/Get-JCEventCount.ps1 @@ -12,21 +12,13 @@ Query the API for a count of matching events curl -X POST 'https://api.jumpcloud.com/insights/directory/v1/events/count' -H 'Content-Type: application/json' -H 'x-api-key: REPLACE_KEY_VALUE' --data '{\"service\": [\"all\"], \"start_time\": \"2021-07-14T23:00:00Z\", \"end_time\": \"2021-07-28T14:00:00Z\", \"sort\": \"DESC\", \"fields\": [\"timestamp\", \"event_type\", \"initiated_by\", \"success\", \"client_ip\", \"provider\", \"organization\"]}' ``` .Example -PS C:\> Get-JCEventCount -Service:('all') -StartTime:((Get-date).AddDays(-30)) +PS C:\> {{ Add code here }} -Pull all event records from a specified time and count the results +{{ Add output here }} .Example -PS C:\> Get-JCEventCount -Service:('sso') -StartTime:('2020-04-14T00:00:00Z') +PS C:\> {{ Add code here }} -Pull all SSO event records from a specified time and count the results -.Example -PS C:\> Get-JCEventCount -Service:('all') -StartTime:('2020-04-14T00:00:00Z') -EndTime:('2020-04-20T23:00:00Z') -SearchTermAnd @{"event_type" = "admin_login_attempt"; "resource.email" = "admin.user@adminbizorg.com"} - -Get all events counts between a date range and match event_type = admin_login_attempt and resource.email = admin.user@adminbizorg.com -.Example -PS C:\> Get-JCEventCount -Service:('directory') -StartTime:((Get-date).AddDays(-30)) -searchTermAnd:@{"event_type" = "group_create"} - -Get only group_create event counts the last thirty days +{{ Add output here }} .Inputs JumpCloud.SDK.DirectoryInsights.Models.IEventQuery diff --git a/PowerShell/JumpCloud Module/Public/Groups/SystemGroups/Add-JCSystemGroupMember.ps1 b/PowerShell/JumpCloud Module/Public/Groups/SystemGroups/Add-JCSystemGroupMember.ps1 index 3e86fcdfd..e3b6d4cbd 100644 --- a/PowerShell/JumpCloud Module/Public/Groups/SystemGroups/Add-JCSystemGroupMember.ps1 +++ b/PowerShell/JumpCloud Module/Public/Groups/SystemGroups/Add-JCSystemGroupMember.ps1 @@ -102,12 +102,11 @@ SystemID has an Alias of _id. This means you can leverage the PowerShell pipelin $jsonbody = $body | ConvertTo-Json Write-Debug $jsonbody - - $GroupAdd = Set-JcSdkSystemGroupMember -GroupId $GroupID -Body $body -ErrorVariable addError -ErrorAction SilentlyContinue - if ($addError) { - $Status = $addError.ErrorDetails.Message - } else { + try { + $GroupAdds = Set-JcSdkSystemGroupMember -GroupId $GroupID -Body $body $Status = 'Added' + } catch { + $Status = $_.Exception.Message } $FormattedResults = [PSCustomObject]@{ @@ -143,11 +142,11 @@ SystemID has an Alias of _id. This means you can leverage the PowerShell pipelin Write-Debug $jsonbody - $GroupAdd = Set-JcSdkSystemGroupMember -GroupId $GroupID -Body $body -ErrorVariable addError -ErrorAction SilentlyContinue - if ($addError) { - $Status = $addError.ErrorDetails.Message - } else { + try { + $GroupAdds = Set-JcSdkSystemGroupMember -GroupId $GroupID -Body $body $Status = 'Added' + } catch { + $Status = $_.Exception.Message } $FormattedResults = [PSCustomObject]@{ diff --git a/PowerShell/JumpCloud Module/Public/Groups/SystemGroups/Remove-JCSystemGroupMember.ps1 b/PowerShell/JumpCloud Module/Public/Groups/SystemGroups/Remove-JCSystemGroupMember.ps1 index 82dd25e45..f1da29bb8 100644 --- a/PowerShell/JumpCloud Module/Public/Groups/SystemGroups/Remove-JCSystemGroupMember.ps1 +++ b/PowerShell/JumpCloud Module/Public/Groups/SystemGroups/Remove-JCSystemGroupMember.ps1 @@ -70,11 +70,11 @@ The SystemID will be the 24 character string populated for the _id field. System $jsonbody = $body | ConvertTo-Json Write-Debug $jsonbody - $GroupRemove = Set-JcSdkSystemGroupMember -GroupId $GroupID -Body $body -ErrorVariable removeError -ErrorAction SilentlyContinue - if ($removeError) { - $Status = $removeError.ErrorDetails.Message - } else { + try { + $GroupRemove = Set-JcSdkSystemGroupMember -GroupId $GroupID -Body $body $Status = 'Removed' + } catch { + $Status = $_.Exception.Message } $FormattedResults = [PSCustomObject]@{ @@ -110,11 +110,11 @@ The SystemID will be the 24 character string populated for the _id field. System Write-Debug $jsonbody - $GroupRemove = Set-JcSdkSystemGroupMember -GroupId $GroupID -Body $body -ErrorVariable removeError -ErrorAction SilentlyContinue - if ($removeError) { - $Status = $removeError.ErrorDetails.Message - } else { + try { + $GroupRemove = Set-JcSdkSystemGroupMember -GroupId $GroupID -Body $body $Status = 'Removed' + } catch { + $Status = $_.Exception.Message } $FormattedResults = [PSCustomObject]@{ diff --git a/PowerShell/JumpCloud Module/Public/Groups/UserGroups/Add-JCUserGroupMember.ps1 b/PowerShell/JumpCloud Module/Public/Groups/UserGroups/Add-JCUserGroupMember.ps1 index ac1ecca5a..79fe08f73 100644 --- a/PowerShell/JumpCloud Module/Public/Groups/UserGroups/Add-JCUserGroupMember.ps1 +++ b/PowerShell/JumpCloud Module/Public/Groups/UserGroups/Add-JCUserGroupMember.ps1 @@ -100,11 +100,11 @@ UserID has an Alias of _id. This means you can leverage the PowerShell pipeline Write-Debug $jsonbody - $GroupAdd = Set-JcSdkUserGroupMember -GroupId $GroupID -Body $body -ErrorVariable addError -ErrorAction SilentlyContinue - if ($addError) { - $Status = $addError.ErrorDetails.Message - } else { + try { + $GroupAdd = Set-JcSdkUserGroupMember -GroupId $GroupID -Body $body $Status = 'Added' + } catch { + $Status = $_.Exception.Message } $FormattedResults = [PSCustomObject]@{ @@ -159,13 +159,14 @@ UserID has an Alias of _id. This means you can leverage the PowerShell pipeline Write-Debug $jsonbody - $GroupAdd = Set-JcSdkUserGroupMember -GroupId $GroupID -Body $body -ErrorVariable addError -ErrorAction SilentlyContinue - if ($addError) { - $Status = $addError.ErrorDetails.Message - } else { + try { + $GroupAdd = Set-JcSdkUserGroupMember -GroupId $GroupID -Body $body $Status = 'Added' + } catch { + $Status = $_.Exception.Message } + $FormattedResults = [PSCustomObject]@{ 'Group' = $GroupID diff --git a/PowerShell/JumpCloud Module/Public/Groups/UserGroups/Remove-JCUserGroupMember.ps1 b/PowerShell/JumpCloud Module/Public/Groups/UserGroups/Remove-JCUserGroupMember.ps1 index 0be30b443..4be6161b8 100644 --- a/PowerShell/JumpCloud Module/Public/Groups/UserGroups/Remove-JCUserGroupMember.ps1 +++ b/PowerShell/JumpCloud Module/Public/Groups/UserGroups/Remove-JCUserGroupMember.ps1 @@ -76,11 +76,11 @@ The UserID will be the 24 character string populated for the _id field. UserID h $jsonbody = $body | ConvertTo-Json Write-Debug $jsonbody - $GroupRemove = Set-JcSdkUserGroupMember -GroupId $GroupID -Body $body -ErrorVariable removeError -ErrorAction SilentlyContinue - if ($removeError) { - $Status = $removeError.ErrorDetails.Message - } else { + try { + $GroupRemove = Set-JcSdkUserGroupMember -GroupId $GroupID -Body $body $Status = 'Removed' + } catch { + $Status = $_.Exception.Message } $FormattedResults = [PSCustomObject]@{ @@ -109,11 +109,11 @@ The UserID will be the 24 character string populated for the _id field. UserID h $jsonbody = $body | ConvertTo-Json Write-Debug $jsonbody - $GroupRemove = Set-JcSdkUserGroupMember -GroupId $GroupID -Body $body -ErrorVariable removeError -ErrorAction SilentlyContinue - if ($removeError) { - $Status = $removeError.ErrorDetails.Message - } else { + try { + $GroupRemove = Set-JcSdkUserGroupMember -GroupId $GroupID -Body $body $Status = 'Removed' + } catch { + $Status = $_.Exception.Message } $FormattedResults = [PSCustomObject]@{ diff --git a/PowerShell/JumpCloud Module/Public/Systems/Get-JCSystem.ps1 b/PowerShell/JumpCloud Module/Public/Systems/Get-JCSystem.ps1 index da28dd13d..36e1888ac 100644 --- a/PowerShell/JumpCloud Module/Public/Systems/Get-JCSystem.ps1 +++ b/PowerShell/JumpCloud Module/Public/Systems/Get-JCSystem.ps1 @@ -152,8 +152,8 @@ Function Get-JCSystem () { [Parameter( ValueFromPipelineByPropertyName, ParameterSetName = 'SearchFilter', - HelpMessage = 'Allows you to return select properties on JumpCloud system objects. Specifying what properties are returned can drastically increase the speed of the API call with a large data set. Valid properties that can be returned are: ''created'', ''active'', ''agentVersion'', ''allowMultiFactorAuthentication'', ''allowPublicKeyAuthentication'', ''allowSshPasswordAuthentication'', ''allowSshRootLogin'', ''arch'', ''created'', ''displayName'', ''hostname'', ''lastContact'', ''modifySSHDConfig'', ''organization'', ''os'', ''remoteIP'', ''serialNumber'', ''sshdParams'', ''systemTimezone'', ''templateName'', ''version''')] - [ValidateSet('acknowledged', 'active', 'agentVersion', 'allowMultiFactorAuthentication', 'allowPublicKeyAuthentication', 'allowSshPasswordAuthentication', 'allowSshRootLogin', 'arch', 'azureAdJoined', 'connectionHistory', 'created', 'displayName', 'domainInfo', 'fde', 'fileSystem', 'hasServiceAccount', 'hostname', 'lastContact', 'mdm', 'modifySSHDConfig', 'networkInterfaces', 'organization', 'os', 'osFamily', 'provisionMetadata', 'remoteIP', 'serialNumber', 'serviceAccountState', 'sshdParams', 'systemInsights', 'systemTimezone', 'systemToken', 'templateName', 'userMetrics', 'usernameHashes', 'version')] + HelpMessage = 'Allows you to return select properties on JumpCloud system objects. Specifying what properties are returned can drastically increase the speed of the API call with a large data set. Valid properties that can be returned are: ''created'', ''active'', ''agentVersion'', ''allowMultiFactorAuthentication'', ''allowPublicKeyAuthentication'', ''allowSshPasswordAuthentication'', ''allowSshRootLogin'', ''arch'', ''created'', ''displayName'', ''hostname'', ''lastContact'', ''modifySSHDConfig'', ''organization'', ''os'', ''remoteIP'', ''serialNumber'', ''sshdParams'', ''systemTimezone'', ''templateName'', ''version'', ''hwVendor'',''secureLogin'',''displayManager'',''amazonInstanceID'',''archFamily'',''builtInCommands'',''description'',''osVersionDetail'',''policyStats'',''desktopCapable'', ''sshRootEnabled''')] + [ValidateSet('acknowledged', 'active', 'agentVersion', 'allowMultiFactorAuthentication', 'allowPublicKeyAuthentication', 'allowSshPasswordAuthentication', 'allowSshRootLogin', 'arch', 'azureAdJoined', 'connectionHistory', 'created', 'displayName', 'domainInfo', 'fde', 'fileSystem', 'hasServiceAccount', 'hostname', 'lastContact', 'mdm', 'modifySSHDConfig', 'networkInterfaces', 'organization', 'os', 'osFamily', 'provisionMetadata', 'remoteIP', 'serialNumber', 'serviceAccountState', 'sshdParams', 'systemInsights', 'systemTimezone', 'systemToken', 'templateName', 'userMetrics', 'usernameHashes', 'version', 'hwVendor', 'secureLogin', 'displayManager', 'amazonInstanceID', 'archFamily', 'builtInCommands', 'description', 'osVersionDetail', 'policyStats', 'desktopCapable', 'sshRootEnabled')] [String[]]$returnProperties ) diff --git a/PowerShell/JumpCloud Module/Public/Users/Get-JCUser.ps1 b/PowerShell/JumpCloud Module/Public/Users/Get-JCUser.ps1 index d23cd3e48..3ed79626a 100644 --- a/PowerShell/JumpCloud Module/Public/Users/Get-JCUser.ps1 +++ b/PowerShell/JumpCloud Module/Public/Users/Get-JCUser.ps1 @@ -72,8 +72,8 @@ Function Get-JCUser () { [ValidateSet('created', 'password_expiration_date')] [String]$filterDateProperty, - [Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'SearchFilter', HelpMessage = 'Allows you to return select properties on JumpCloud user objects. Specifying what properties are returned can drastically increase the speed of the API call with a large data set. Valid properties that can be returned are: ''created'', ''password_expiration_date'', ''account_locked'', ''activated'', ''addresses'', ''allow_public_key'', ''attributes'', ''alternateEmail'',''email'', ''enable_managed_uid'', ''enable_user_portal_multifactor'', ''externally_managed'', ''firstname'', ''lastname'', ''ldap_binding_user'', ''passwordless_sudo'', ''password_expired'', ''password_never_expires'', ''phoneNumbers'', ''samba_service_user'', ''ssh_keys'', ''sudo'', ''totp_enabled'', ''unix_guid'', ''unix_uid'', ''managedAppleId'',''manager'',''username'',''suspended'',''recoveryEmail'',''systemUsername''')] - [ValidateSet('created', 'password_expiration_date', 'account_locked', 'activated', 'addresses', 'allow_public_key', 'attributes', 'alternateEmail', 'recoveryEmail', 'managedAppleId', 'manager', 'email', 'enable_managed_uid', 'enable_user_portal_multifactor', 'externally_managed', 'firstname', 'lastname', 'ldap_binding_user', 'passwordless_sudo', 'password_expired', 'password_never_expires', 'phoneNumbers', 'samba_service_user', 'ssh_keys', 'sudo', 'totp_enabled', 'unix_guid', 'unix_uid', 'username', 'middlename', 'displayname', 'jobTitle', 'employeeIdentifier', 'department', 'costCenter', 'company', 'employeeType', 'description', 'location', 'external_source_type', 'external_dn', 'suspended', 'mfa', 'recoveryEmail', 'systemUsername')] + [Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'SearchFilter', HelpMessage = 'Allows you to return select properties on JumpCloud user objects. Specifying what properties are returned can drastically increase the speed of the API call with a large data set. Valid properties that can be returned are: ''created'', ''password_expiration_date'', ''account_locked'', ''activated'', ''addresses'', ''allow_public_key'', ''attributes'', ''alternateEmail'',''email'', ''enable_managed_uid'', ''enable_user_portal_multifactor'', ''externally_managed'', ''firstname'', ''lastname'', ''ldap_binding_user'', ''passwordless_sudo'', ''password_expired'', ''password_never_expires'', ''phoneNumbers'', ''samba_service_user'', ''ssh_keys'', ''sudo'', ''totp_enabled'', ''unix_guid'', ''unix_uid'', ''managedAppleId'',''manager'',''username'',''suspended'',''recoveryEmail'',''systemUsername'',''relationships'',''public_key'',''external_password_expiration_date'',''disableDeviceMaxLoginAttempts'',''password'',''state''')] + [ValidateSet('created', 'password_expiration_date', 'account_locked', 'activated', 'addresses', 'allow_public_key', 'attributes', 'alternateEmail', 'recoveryEmail', 'managedAppleId', 'manager', 'email', 'enable_managed_uid', 'enable_user_portal_multifactor', 'externally_managed', 'firstname', 'lastname', 'ldap_binding_user', 'passwordless_sudo', 'password_expired', 'password_never_expires', 'phoneNumbers', 'samba_service_user', 'ssh_keys', 'sudo', 'totp_enabled', 'unix_guid', 'unix_uid', 'username', 'middlename', 'displayname', 'jobTitle', 'employeeIdentifier', 'department', 'costCenter', 'company', 'employeeType', 'description', 'location', 'external_source_type', 'external_dn', 'suspended', 'mfa', 'recoveryEmail', 'systemUsername', 'relationships', 'public_key', 'external_password_expiration_date', 'disableDeviceMaxLoginAttempts', 'password', 'state')] [String[]]$returnProperties, #New parameters as of 1.8 release diff --git a/PowerShell/JumpCloud Module/Tests/ModuleValidation/ReturnProperties.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/ModuleValidation/ReturnProperties.Tests.ps1 new file mode 100644 index 000000000..81d6e0539 --- /dev/null +++ b/PowerShell/JumpCloud Module/Tests/ModuleValidation/ReturnProperties.Tests.ps1 @@ -0,0 +1,57 @@ +Describe -Tag:('ModuleValidation') 'Return Properties Checks' { + It 'Validates that functions with "Return Properties" return up-to-date fields' { + $validFunction = @('Get-JCSystem', 'Get-JCUser', 'Get-JCCommand') + $functionHash = @{ + 'Get-JCSystem' = @{ + 'modelDefinition' = 'definitions.system.properties' + 'customDefinitionMap' = @{ + + } + 'ignoreList' = @('_id', 'tags') + }; + 'Get-JCUser' = @{ + 'modelDefinition' = 'definitions.systemuserput.properties' + 'customDefinitionMap' = @{ + + } + 'ignoreList' = @('_id', 'tags') + }; + 'Get-JCCommand' = @{ + 'modelDefinition' = 'definitions.command.properties' + 'customDefinitionMap' = @{ + + } + }; + } + $swaggerV1Url = "https://docs.jumpcloud.com/api/1.0/index.yaml" + $swaggerContent = Invoke-WebRequest -Uri $swaggerV1Url -Method 'Get' + $swagger = $swaggerContent.content | ConvertFrom-Yaml + + foreach ($item in $functionHash.keys) { + Write-host "$($item.keys)" + #get the command file: + $command = Get-Command -name $item + $commandRetAttributes = $command.Parameters.returnProperties.attributes.validValues + $commandList = New-Object System.Collections.ArrayList + foreach ($collection in $commandRetAttributes) { + $commandList.Add($collection) | Out-Null + } + $swaggerRetAttributes = invoke-Expression ('$swagger.' + $functionHash[$item].modelDefinition) + $swaggerList = New-Object System.Collections.ArrayList + foreach ($collection in $swaggerRetAttributes.keys) { + $swaggerList.Add($collection) | Out-Null + } + + $diffList = compare-Object -ReferenceObject $commandList -DifferenceObject $swaggerList + # items in swagger, not module + $inSwaggerNotFunction = $diffList | where-object { $_.SideIndicator -eq "=>" } + $missing = $inSwaggerNotFunction | where-object { $_.InputObject -notin $functionHash[$item].ignoreList } + # there should not be any missing items + if ($missing.InputObject) { + Write-Warning "The folling properties are defined in swagger for the $item function but not the module, either add them to the function validate set or add them to the ignore list in this test" + Write-host $missing.InputObject + } + $missing.InputObject | should -BeNullOrEmpty + } + } +} diff --git a/PowerShell/JumpCloud Module/Tests/Public/Directory/Add-JCGsuiteMember.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Directory/Add-JCGsuiteMember.Tests.ps1 index 0b77bce37..9f695e5e9 100644 --- a/PowerShell/JumpCloud Module/Tests/Public/Directory/Add-JCGsuiteMember.Tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Directory/Add-JCGsuiteMember.Tests.ps1 @@ -54,13 +54,13 @@ Describe -Tag:('JCCloudDirectory') 'Add-JCGSuiteMember' { $User.Status | Should -Be 'Added' } It 'Attempts to add user by username and userid' { - {Add-JCGsuiteMember -Name $Directories.Name -Username $NewUser.username -userID $NewUser.ID} | Should -Throw + { Add-JCGsuiteMember -Name $Directories.Name -Username $NewUser.username -userID $NewUser.ID } | Should -Throw } It 'Attempts to add userGroup by name and ID' { - {Add-JCGsuiteMember -Name $Directories.Name -GroupID $NewGroup.ID -GroupName $NewGroup.Name} | Should -Throw + { Add-JCGsuiteMember -Name $Directories.Name -GroupID $NewGroup.ID -GroupName $NewGroup.Name } | Should -Throw } It 'Attempts to add a user and a usergroup' { - {Add-JCGsuiteMember -Name $Directories.Name -GroupID $NewGroup.ID -UserID $NewUser.ID} | Should -Throw + { Add-JCGsuiteMember -Name $Directories.Name -GroupID $NewGroup.ID -UserID $NewUser.ID } | Should -Throw } It 'Attempts to add a non-existent user' { { $User = Add-JCGsuiteMember -Name $Directories.Name -Username "Dummy.User" } | Should -Throw @@ -73,8 +73,16 @@ Describe -Tag:('JCCloudDirectory') 'Add-JCGSuiteMember' { $Group.Status | Should -BeLike 'Bad Request*' } AfterEach { - Set-JcSdkGSuiteAssociation -GsuiteId $Directories.Id -Id $NewUser.Id -Type user -Op 'remove' -ErrorAction SilentlyContinue - Set-JcSdkGSuiteAssociation -GsuiteId $Directories.Id -Id $NewGroup.Id -Type user_group -Op 'remove' -ErrorAction SilentlyContinue + try { + Set-JcSdkGSuiteAssociation -GsuiteId $Directories.Id -Id $NewUser.Id -Type user -Op 'remove' -ErrorAction SilentlyContinue + } catch { + Write-Debug "Google Workspace Directory: $($Directories.Id) was not associated with userID: $($NewUser.Id)) " + } + try { + Set-JcSdkGSuiteAssociation -GsuiteId $Directories.Id -Id $NewGroup.Id -Type user_group -Op 'remove' -ErrorAction SilentlyContinue + } catch { + Write-Debug "Google Workspace Directory: $($Directories.Id) was not associated with userGroupID: $($NewGroup.Id) " + } } AfterAll { Remove-JCUser -UserID $NewUser.Id -force diff --git a/PowerShell/JumpCloud Module/Tests/Public/Directory/Add-JCOffice365Member.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Directory/Add-JCOffice365Member.Tests.ps1 index 3491bea46..d835ac656 100644 --- a/PowerShell/JumpCloud Module/Tests/Public/Directory/Add-JCOffice365Member.Tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Directory/Add-JCOffice365Member.Tests.ps1 @@ -54,13 +54,13 @@ Describe -Tag:('JCCloudDirectory') 'Add-JCOffice365Member' { $User.Status | Should -Be 'Added' } It 'Attempts to add user by username and userid' { - {Add-JCOffice365Member -Name $Directories.Name -Username $NewUser.username -userID $NewUser.ID} | Should -Throw + { Add-JCOffice365Member -Name $Directories.Name -Username $NewUser.username -userID $NewUser.ID } | Should -Throw } It 'Attempts to add userGroup by name and ID' { - {Add-JCOffice365Member -Name $Directories.Name -GroupID $NewGroup.ID -GroupName $NewGroup.Name} | Should -Throw + { Add-JCOffice365Member -Name $Directories.Name -GroupID $NewGroup.ID -GroupName $NewGroup.Name } | Should -Throw } It 'Attempts to add a user and a usergroup' { - {Add-JCOffice365Member -Name $Directories.Name -GroupID $NewGroup.ID -UserID $NewUser.ID} | Should -Throw + { Add-JCOffice365Member -Name $Directories.Name -GroupID $NewGroup.ID -UserID $NewUser.ID } | Should -Throw } It 'Attempts to add a non-existent user' { { $User = Add-JCOffice365Member -Name $Directories.Name -Username "Dummy.User" } | Should -Throw @@ -73,8 +73,16 @@ Describe -Tag:('JCCloudDirectory') 'Add-JCOffice365Member' { $Group.Status | Should -BeLike 'Bad Request*' } AfterEach { - Set-JcSdkOffice365Association -Office365Id $Directories.Id -Id $NewUser.Id -Type user -Op 'remove' -ErrorAction SilentlyContinue - Set-JcSdkOffice365Association -Office365Id $Directories.Id -Id $NewGroup.Id -Type user_group -Op 'remove' -ErrorAction SilentlyContinue + try { + Set-JcSdkOffice365Association -Office365Id $Directories.Id -Id $NewUser.Id -Type user -Op 'remove' -ErrorAction SilentlyContinue + } catch { + Write-Debug "Office 365 Directory: $($Directories.Id) was not associated with userID: $($NewUser.Id)) " + } + try { + Set-JcSdkOffice365Association -Office365Id $Directories.Id -Id $NewGroup.Id -Type user_group -Op 'remove' -ErrorAction SilentlyContinue + } catch { + Write-Debug "Office 365 Directory: $($Directories.Id) was not associated with userGroupID: $($NewGroup.Id) " + } } AfterAll { Remove-JCUser -UserID $NewUser.Id -force diff --git a/PowerShell/JumpCloud Module/Tests/Public/Directory/Remove-JCGsuiteMember.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Directory/Remove-JCGsuiteMember.Tests.ps1 index 666a113f0..f2129d9df 100644 --- a/PowerShell/JumpCloud Module/Tests/Public/Directory/Remove-JCGsuiteMember.Tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Directory/Remove-JCGsuiteMember.Tests.ps1 @@ -57,13 +57,13 @@ Describe -Tag:('JCCloudDirectory') 'Remove-JCGsuiteMember' { $User.Status | Should -Be 'Removed' } It 'Attempts to remove user by username and userid' { - {Remove-JCGsuiteMember -Name $Directories.Name -Username $NewUser.username -userID $NewUser.ID} | Should -Throw + { Remove-JCGsuiteMember -Name $Directories.Name -Username $NewUser.username -userID $NewUser.ID } | Should -Throw } It 'Attempts to remove userGroup by name and ID' { - {Remove-JCGsuiteMember -Name $Directories.Name -GroupID $NewGroup.ID -GroupName $NewGroup.Name} | Should -Throw + { Remove-JCGsuiteMember -Name $Directories.Name -GroupID $NewGroup.ID -GroupName $NewGroup.Name } | Should -Throw } It 'Attempts to remove a user and a usergroup' { - {Remove-JCGsuiteMember -Name $Directories.Name -GroupID $NewGroup.ID -UserID $NewUser.ID} | Should -Throw + { Remove-JCGsuiteMember -Name $Directories.Name -GroupID $NewGroup.ID -UserID $NewUser.ID } | Should -Throw } It 'Attempts to remove a non-existent user' { { $User = Remove-JCGsuiteMember -Name $Directories.Name -Username "Dummy.User" } | Should -Throw @@ -76,8 +76,16 @@ Describe -Tag:('JCCloudDirectory') 'Remove-JCGsuiteMember' { $Group.Status | Should -BeLike 'Bad Request*' } AfterEach { - Set-JcSdkGSuiteAssociation -GsuiteId $Directories.Id -Id $NewUser.Id -Type user -Op 'add' -ErrorAction SilentlyContinue - Set-JcSdkGSuiteAssociation -GsuiteId $Directories.Id -Id $NewGroup.Id -Type user_group -Op 'add' -ErrorAction SilentlyContinue + try { + Set-JcSdkGSuiteAssociation -GsuiteId $Directories.Id -Id $NewUser.Id -Type user -Op 'add' -ErrorAction SilentlyContinue + } catch { + Write-Debug "Google Workspace Directory: $($Directories.Id) was not associated with userID: $($NewUser.Id)) " + } + try { + Set-JcSdkGSuiteAssociation -GsuiteId $Directories.Id -Id $NewGroup.Id -Type user_group -Op 'add' -ErrorAction SilentlyContinue + } catch { + Write-Debug "Google Workspace Directory: $($Directories.Id) was not associated with userGroupID: $($NewGroup.Id) " + } } AfterAll { Remove-JCUser -UserID $NewUser.Id -force diff --git a/PowerShell/JumpCloud Module/Tests/Public/Directory/Remove-JCOffice365Member.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Directory/Remove-JCOffice365Member.Tests.ps1 index 78dc60fe7..108dc27ce 100644 --- a/PowerShell/JumpCloud Module/Tests/Public/Directory/Remove-JCOffice365Member.Tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Directory/Remove-JCOffice365Member.Tests.ps1 @@ -57,13 +57,13 @@ Describe -Tag:('JCCloudDirectory') 'Remove-JCOffice365Member' { $User.Status | Should -Be 'Removed' } It 'Attempts to remove user by username and userid' { - {Remove-JCOffice365Member -Name $Directories.Name -Username $NewUser.username -userID $NewUser.ID} | Should -Throw + { Remove-JCOffice365Member -Name $Directories.Name -Username $NewUser.username -userID $NewUser.ID } | Should -Throw } It 'Attempts to remove userGroup by name and ID' { - {Remove-JCOffice365Member -Name $Directories.Name -GroupID $NewGroup.ID -GroupName $NewGroup.Name} | Should -Throw + { Remove-JCOffice365Member -Name $Directories.Name -GroupID $NewGroup.ID -GroupName $NewGroup.Name } | Should -Throw } It 'Attempts to remove a user and a usergroup' { - {Remove-JCOffice365Member -Name $Directories.Name -GroupID $NewGroup.ID -UserID $NewUser.ID} | Should -Throw + { Remove-JCOffice365Member -Name $Directories.Name -GroupID $NewGroup.ID -UserID $NewUser.ID } | Should -Throw } It 'Attempts to remove a non-existent user' { { $User = Remove-JCOffice365Member -Name $Directories.Name -Username "Dummy.User" } | Should -Throw @@ -76,8 +76,16 @@ Describe -Tag:('JCCloudDirectory') 'Remove-JCOffice365Member' { $Group.Status | Should -BeLike 'Bad Request*' } AfterEach { - Set-JcSdkOffice365Association -Office365Id $Directories.Id -Id $NewUser.Id -Type user -Op 'add' -ErrorAction SilentlyContinue - Set-JcSdkOffice365Association -Office365Id $Directories.Id -Id $NewGroup.Id -Type user_group -Op 'add' -ErrorAction SilentlyContinue + try { + Set-JcSdkOffice365Association -Office365Id $Directories.Id -Id $NewUser.Id -Type user -Op 'add' -ErrorAction SilentlyContinue + } catch { + Write-Debug "Office 365 Directory: $($Directories.Id) was not associated with userID: $($NewUser.Id)) " + } + try { + Set-JcSdkOffice365Association -Office365Id $Directories.Id -Id $NewGroup.Id -Type user_group -Op 'add' -ErrorAction SilentlyContinue + } catch { + Write-Debug "Office 365 Directory: $($Directories.Id) was not associated with userGroupID: $($NewGroup.Id) " + } } AfterAll { Remove-JCUser -UserID $NewUser.Id -force diff --git a/PowerShell/JumpCloud Module/Tests/SetupOrg.ps1 b/PowerShell/JumpCloud Module/Tests/SetupOrg.ps1 index 934051c4e..76fae7bf9 100644 --- a/PowerShell/JumpCloud Module/Tests/SetupOrg.ps1 +++ b/PowerShell/JumpCloud Module/Tests/SetupOrg.ps1 @@ -50,14 +50,24 @@ Try { } # Remove all groups from an org If ($Groups) { - # TODO: if system group is assigned to MDM this will throw an error - $null = Get-JCGroup | ForEach-Object { - If ($_.Type -eq 'system_group') { - # write-host $_.Name - Remove-JcSdkSystemGroup -Id $_.id -ErrorAction Ignore - } elseif ($_.Type -eq 'user_group') { - # write-host $_.Name - Remove-JcSdkUserGroup -Id $_.id -ErrorAction Ignore + $AllGroupsToRemove = Get-JCGroup + foreach ($group in $allGroupsToRemove) { + write-host "Group Name: $($group.Name) $($group.id) $($group.type)" + switch ($group.type) { + 'system_group' { + try { + Remove-JcSdkSystemGroup -Id $group.id -ErrorAction Ignore -errorVariable groupError + } catch { + if ($groupError.ErrorRecord -Match "default macOS ADE device group") { + Set-JCsdkSystemGroup -Id $group.id -Name "MDM-$(Get-Random)" + } else { + Set-JCsdkSystemGroup -Id $group.id -Name "unknown-$(Get-Random)" + } + } + } + 'user_group' { + Remove-JcSdkUserGroup -Id $group.id -ErrorAction Ignore + } } } Write-Host "[status] Removed groups: $($stopwatch.Elapsed)" diff --git a/PowerShell/ModuleChangelog.md b/PowerShell/ModuleChangelog.md index 010c9bf6d..6e3b6d5a2 100644 --- a/PowerShell/ModuleChangelog.md +++ b/PowerShell/ModuleChangelog.md @@ -1,3 +1,17 @@ +## 2.10.1 + +Release Date: April 2, 2024 + +#### RELEASE NOTES + +``` +Added several missing filter fields to Get-JCUser, Get-JCSystem, Get-JCCommand +``` + +#### FEATURES: + +Additional `returnProperties` added to Get-JCUser, Get-JCSystem, Get-JCCommand functions + ## 2.10.0 Release Date: January 17, 2024 @@ -15,7 +29,6 @@ Add-JCOffice365Member - Add a user or user group to an Office365 instance Remove-JCGsuiteMember - Remove a user or user group from a Gsuite instance Remove-JCOffice365Member - Remove a user or user group from an Office365 instance - ## 2.9.1 Release Date: January 11, 2024