diff --git a/PowerShell/Deploy/Functions/Get-PSGalleryModuleVersion.ps1 b/PowerShell/Deploy/Functions/Get-PSGalleryModuleVersion.ps1 index 079ee10c8..5b4e302dc 100755 --- a/PowerShell/Deploy/Functions/Get-PSGalleryModuleVersion.ps1 +++ b/PowerShell/Deploy/Functions/Get-PSGalleryModuleVersion.ps1 @@ -2,7 +2,7 @@ Function Get-PSGalleryModuleVersion { Param ( [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)][ValidateNotNullOrEmpty()][string]$Name, - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)][ValidateNotNullOrEmpty()][ValidateSet('Major', 'Minor', 'Patch')][string]$RELEASETYPE + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)][ValidateNotNullOrEmpty()][ValidateSet('Major', 'Minor', 'Patch', 'Manual')][string]$RELEASETYPE ) # Check to see if module already exists to set version number $PowerShellGalleryModule = Find-Module -Name:($Name) -ErrorAction:('Ignore') @@ -48,7 +48,12 @@ Function Get-PSGalleryModuleVersion } } - $NextVersion = ($ModuleVersion.Major, $ModuleVersion.Minor, $ModuleVersion.Patch) -join '.' + if ($RELEASETYPE -eq 'Manual'){ + $NextVersion = ($Psd1).ModuleVersion + } + else { + $NextVersion = ($ModuleVersion.Major, $ModuleVersion.Minor, $ModuleVersion.Patch) -join '.' + } Add-Member -InputObject:($ModuleVersion) -MemberType:('NoteProperty') -Name:('NextVersion') -Value:($NextVersion) Return $ModuleVersion } \ No newline at end of file diff --git a/PowerShell/Deploy/Get-Config.ps1 b/PowerShell/Deploy/Get-Config.ps1 index c19887674..2a636f5c3 100755 --- a/PowerShell/Deploy/Get-Config.ps1 +++ b/PowerShell/Deploy/Get-Config.ps1 @@ -40,6 +40,9 @@ $RequiredFiles | ForEach-Object { # Get module function names $Functions_Public = If (Test-Path -Path:($FolderPath_Public)) { Get-ChildItem -Path:($FolderPath_Public + '/' + '*.ps1') -Recurse } $Functions_Private = If (Test-Path -Path:($FolderPath_Private)) { Get-ChildItem -Path:($FolderPath_Private + '/' + '*.ps1') -Recurse } +# Get psd1 contents +$Psd1 = Import-PowerShellDataFile -Path:($FilePath_psd1) +$RequiredModules = $Psd1.RequiredModules # Load deploy functions $DeployFunctions = @(Get-ChildItem -Path:($PSScriptRoot + '/Functions/*.ps1') -Recurse) Foreach ($DeployFunction In $DeployFunctions) diff --git a/PowerShell/Deploy/SdkSync/jcapiToSupportSync.ps1 b/PowerShell/Deploy/SdkSync/jcapiToSupportSync.ps1 new file mode 100644 index 000000000..62ef6e747 --- /dev/null +++ b/PowerShell/Deploy/SdkSync/jcapiToSupportSync.ps1 @@ -0,0 +1,108 @@ +. ((Get-Item -Path:($PSScriptRoot)).Parent.FullName + '/' + 'Get-Config.ps1') +########################################################################### +Install-Module -Name:('PSScriptAnalyzer') -Force +$ApprovedFunctions = [Ordered]@{ + 'JumpCloud.SDK.DirectoryInsights' = @( + [PSCustomObject]@{ + Destination = '/Public/DirectoryInsights' + Name = 'Get-JcSdkEvent' + }, + [PSCustomObject]@{ + Destination = '/Public/DirectoryInsights' + Name = 'Get-JcSdkEventCount' + } + ) +} +$SdkPrefix = 'JcSdk' +$JumpCloudModulePrefix = 'JC' +$IndentChar = ' ' +$MSCopyrightHeader = "`n# ----------------------------------------------------------------------------------`n#`n# Copyright Microsoft Corporation`n# Licensed under the Apache License, Version 2.0 (the ""License"");`n# you may not use this file except in compliance with the License.`n# You may obtain a copy of the License at`n# http://www.apache.org/licenses/LICENSE-2.0`n# Unless required by applicable law or agreed to in writing, software`n# distributed under the License is distributed on an ""AS IS"" BASIS,`n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.`n# See the License for the specific language governing permissions and`n# limitations under the License.`n# ----------------------------------------------------------------------------------`n" +$Divider = '|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|' +$FunctionTemplate = "{0}`nFunction {1}`n{{`n$($IndentChar){2}`n$($IndentChar)Param(`n{3}`n$($IndentChar))`n$($IndentChar)Begin`n$($IndentChar){{`n{4}`n$($IndentChar)}}`n$($IndentChar)Process`n$($IndentChar){{`n{5}`n$($IndentChar)}}`n$($IndentChar)End`n$($IndentChar){{`n{6}`n$($IndentChar)}}`n}}" +$ScriptAnalyzerResults = @() +$JumpCloudModulePath = (Get-Item -Path:($PSScriptRoot)).Parent.Parent.FullName + '/JumpCloud Module' +Import-Module -Name:($RequiredModules) +Get-Module -Refresh -ListAvailable -All | Out-Null +$Modules = Get-Module -Name:($RequiredModules | Where-Object { $_ -in $ApprovedFunctions.Keys }) +If (-not [System.String]::IsNullOrEmpty($Modules)) +{ + ForEach ($Module In $Modules) + { + $ModuleName = $Module.Name + ForEach ($Function In $ApprovedFunctions.$ModuleName) + { + $FunctionName = $Function.Name + $FunctionDestination = $Function.Destination + $OutputPath = "$JumpCloudModulePath/$FunctionDestination" + $Command = Get-Command -Name:($FunctionName) + $CommandName = $Command.Name + $NewCommandName = $CommandName.Replace($SdkPrefix, $JumpCloudModulePrefix) + Write-Host ("[STATUS] Building: $NewCommandName") -BackgroundColor:('Black') -ForegroundColor:('Magenta') + # Get content from sdk function + $CommandFilePath = $Command.ScriptBlock.File + $CommandFilePathContent = Get-Content -Path:($CommandFilePath) -Raw + $FunctionContent = If ($CommandFilePath -like '*ProxyCmdletDefinitions.ps1') + { + <# When the autorest generated module has been installed and imported from the PSGallery all the + cmdlets will exist in a single ProxyCmdletDefinitions.ps1 file. We need to parse + out the specific function in order to gather the parts we need to copy over. #> + $CommandFilePathContent.Replace($MSCopyrightHeader, $Divider).Split($Divider).Where( { $_ -like ('*' + "function $CommandName {" + '*') }) + } + Else + { + <# When the autorest generated module has been imported from a local psd1 module the function will + remain in their individual files. #> + $CommandFilePathContent + } + $PSScriptInfo = ($FunctionContent | Select-String -Pattern:('(?s)(<#)(.*?)(#>)')).Matches.Value + $Params = $FunctionContent | Select-String -Pattern:('(?s)( \[Parameter)(.*?)(\})') -AllMatches + $ParameterContent = ($Params.Matches.Value | Where-Object { $_ -notlike '*DontShow*' -and $_ -notlike '*Limit*' -and $_ -notlike '*Skip*' }) + $OutputType = ($FunctionContent | Select-String -Pattern:('(\[OutputType)(.*?)(\]\r)')).Matches.Value + $CmdletBinding = ($FunctionContent | Select-String -Pattern:('(\[CmdletBinding)(.*?)(\]\r)')).Matches.Value + If (-not [System.String]::IsNullOrEmpty($PSScriptInfo)) + { + $PSScriptInfo = $PSScriptInfo.Replace($SdkPrefix, $JumpCloudModulePrefix) + $PSScriptInfo = $PSScriptInfo.Replace("$NewCommandName.md", "$FunctionName.md") + } + # Build CmdletBinding + If (-not [System.String]::IsNullOrEmpty($OutputType)) { $CmdletBinding = "$($OutputType)`n$($IndentChar)$($CmdletBinding)" } + # Build $BeginContent, $ProcessContent, and $EndContent + $BeginContent = @() + $ProcessContent = @() + $EndContent = @() + # Build "Begin" block + $BeginContent += "$($IndentChar)$($IndentChar)Connect-JCOnline -force | Out-Null" + $BeginContent += "$($IndentChar)$($IndentChar)`$Results = @()" + # Build "Process" block + $ProcessContent += "$($IndentChar)$($IndentChar)`$Results = $($ModuleName)\$($CommandName) @PSBoundParameters" + # Build "End" block + $EndContent += "$($IndentChar)$($IndentChar)Return `$Results" + If (-not [System.String]::IsNullOrEmpty($BeginContent) -and -not [System.String]::IsNullOrEmpty($ProcessContent) -and -not [System.String]::IsNullOrEmpty($EndContent)) + { + # Build "Function" + $NewScript = $FunctionTemplate -f $PSScriptInfo, $NewCommandName, $CmdletBinding, ($ParameterContent -join ",`n`n"), ($BeginContent -join "`n"), ($ProcessContent -join "`n"), ($EndContent -join "`n") + # Fix line endings + $NewScript = $NewScript.Replace("`r`n", "`n").Trim() + # Export the function + $OutputFilePath = "$OutputPath/$NewCommandName.ps1" + New-FolderRecursive -Path:($OutputFilePath) -Force + $NewScript | Out-File -FilePath:($OutputFilePath) -Force + # Validate script syntax + $ScriptAnalyzerResult = Invoke-ScriptAnalyzer -Path:($OutputFilePath) -Recurse -ExcludeRule PSShouldProcess, PSAvoidTrailingWhitespace, PSAvoidUsingWMICmdlet, PSAvoidUsingPlainTextForPassword, PSAvoidUsingUsernameAndPasswordParams, PSAvoidUsingInvokeExpression, PSUseDeclaredVarsMoreThanAssignments, PSUseSingularNouns, PSAvoidGlobalVars, PSUseShouldProcessForStateChangingFunctions, PSAvoidUsingWriteHost, PSAvoidUsingPositionalParameters + If ($ScriptAnalyzerResult) + { + $ScriptAnalyzerResults += $ScriptAnalyzerResult + } + } + # Copy tests? + # Copy-Item -Path:($AutoRest_Tests) -Destination:($JCModule_Tests) -Force + # Update .Psd1 file + $Psd1.FunctionsToExport += $NewCommandName + Update-ModuleManifest -Path:($FilePath_psd1) -FunctionsToExport:($Psd1.FunctionsToExport) + } + } +} +Else +{ + Write-Error ('No modules found!') +} \ No newline at end of file diff --git a/PowerShell/Deploy/Setup-Dependencies.ps1 b/PowerShell/Deploy/Setup-Dependencies.ps1 new file mode 100644 index 000000000..df8afb3a1 --- /dev/null +++ b/PowerShell/Deploy/Setup-Dependencies.ps1 @@ -0,0 +1,18 @@ +. ($PSScriptRoot + '/' + 'Get-Config.ps1') +########################################################################### +ForEach ($RequiredModule In $RequiredModules) +{ + Write-Host("Setting up dependency '$RequiredModule'") + # Check to see if the module is installed + If ([System.String]::IsNullOrEmpty((Get-InstalledModule).Where( { $_.Name -eq $RequiredModule }))) + { + Write-Host("Installing '$RequiredModule'") + Install-Module -Name:($RequiredModule) -Force + } + # Get-Module -Refresh -ListAvailable + If ([System.String]::IsNullOrEmpty((Get-Module).Where( { $_.Name -eq $RequiredModule }))) + { + Write-Host("Importing '$RequiredModule'") + Import-Module -Name:($RequiredModule) -Force + } +} \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Docs/Get-JCEvent.md b/PowerShell/JumpCloud Module/Docs/Get-JCEvent.md index 590d32fea..ada491582 100644 --- a/PowerShell/JumpCloud Module/Docs/Get-JCEvent.md +++ b/PowerShell/JumpCloud Module/Docs/Get-JCEvent.md @@ -14,14 +14,14 @@ Query the API for Directory Insights events ### GetExpanded (Default) ``` -Get-JCEvent [-EndTime ] [-Fields ] [-Limit ] [-SearchAfter ] - [-SearchTermAnd ] [-SearchTermOr ] [-Service ] [-Sort ] - [-StartTime ] [-Paginate ] [-WhatIf] [-Confirm] [] +Get-JCEvent -Service -StartTime [-EndTime ] [-Fields ] + [-SearchAfter ] [-SearchTermAnd ] [-SearchTermOr ] [-Sort ] [-WhatIf] + [-Confirm] [] ``` ### Get ``` -Get-JCEvent -EventQueryBody [-Paginate ] [-WhatIf] [-Confirm] [] +Get-JCEvent -Body [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -87,42 +87,42 @@ Get all events filtered by organization_update term between a date range ## PARAMETERS -### -EventQueryBody -EventQuery is the users' command to search our auth logs -To construct, see NOTES section for EVENTQUERYBODY properties and create a hash table. +### -Service +service name to query. +Known services: systems,radius,sso,directory,ldap,all ```yaml -Type: JumpCloud.SDK.DirectoryInsights.Models.IEventQuery -Parameter Sets: Get +Type: System.String[] +Parameter Sets: GetExpanded Aliases: Required: True Position: Named Default value: None -Accept pipeline input: True (ByValue) +Accept pipeline input: False Accept wildcard characters: False ``` -### -EndTime -optional query end time, UTC in RFC3339 format +### -StartTime +query start time, UTC in RFC3339 format ```yaml Type: System.DateTime Parameter Sets: GetExpanded Aliases: -Required: False +Required: True Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False ``` -### -Fields -optional list of fields to return from query +### -EndTime +optional query end time, UTC in RFC3339 format ```yaml -Type: System.String[] +Type: System.DateTime Parameter Sets: GetExpanded Aliases: @@ -133,17 +133,17 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Limit -Max number of rows to return +### -Fields +optional list of fields to return from query ```yaml -Type: System.Int64 +Type: System.String[] Parameter Sets: GetExpanded Aliases: Required: False Position: Named -Default value: 0 +Default value: None Accept pipeline input: False Accept wildcard characters: False ``` @@ -195,22 +195,6 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Service -service name to query. -Known services: systems,radius,sso,directory,ldap,all - -```yaml -Type: System.String[] -Parameter Sets: GetExpanded -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ### -Sort ASC or DESC order for timestamp @@ -226,33 +210,19 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -StartTime -query start time, UTC in RFC3339 format +### -Body +EventQuery is the users' command to search our auth logs +To construct, see NOTES section for BODY properties and create a hash table. ```yaml -Type: System.DateTime -Parameter Sets: GetExpanded +Type: JumpCloud.SDK.DirectoryInsights.Models.IEventQuery +Parameter Sets: Get Aliases: -Required: False +Required: True Position: Named Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Paginate -Set to $true to return all results. - -```yaml -Type: System.Boolean -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: True -Accept pipeline input: False +Accept pipeline input: True (ByValue) Accept wildcard characters: False ``` diff --git a/PowerShell/JumpCloud Module/Docs/Get-JCEventCount.md b/PowerShell/JumpCloud Module/Docs/Get-JCEventCount.md new file mode 100644 index 000000000..a292e916a --- /dev/null +++ b/PowerShell/JumpCloud Module/Docs/Get-JCEventCount.md @@ -0,0 +1,267 @@ +--- +external help file: JumpCloud-help.xml +Module Name: JumpCloud +online version: https://github.com/TheJumpCloud/support/wiki/Get-JCEventCount +schema: 2.0.0 +--- + +# Get-JCEventCount + +## SYNOPSIS +Query the API for a count of matching events + +## SYNTAX + +### GetExpanded (Default) +``` +Get-JCEventCount -Service -StartTime [-EndTime ] [-Fields ] + [-SearchAfter ] [-SearchTermAnd ] [-SearchTermOr ] [-Sort ] [-WhatIf] + [-Confirm] [] +``` + +### Get +``` +Get-JCEventCount -Body [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION +Query the API for a count of matching events + +## EXAMPLES + +### EXAMPLE 1 +``` +Get-JCEventCount -Service:('all') -StartTime:((Get-date).AddDays(-30)) +``` + +Pull all event records from a specified time and count the results + +### EXAMPLE 2 +``` +Get-JCEventCount -Service:('sso') -StartTime:('2020-04-14T00:00:00Z') +``` + +Pull all SSO event records from a specified time and count the results + +### EXAMPLE 3 +``` +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 4 +``` +Get-JCEventCount -Service:('directory') -StartTime:((Get-date).AddDays(-30)) -searchTermAnd:@{"event_type" = "group_create"} +``` + +Get only group_create event counts the last thirty days + +## PARAMETERS + +### -Service +service name to query. +Known services: systems,radius,sso,directory,ldap,all + +```yaml +Type: System.String[] +Parameter Sets: GetExpanded +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -StartTime +query start time, UTC in RFC3339 format + +```yaml +Type: System.DateTime +Parameter Sets: GetExpanded +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -EndTime +optional query end time, UTC in RFC3339 format + +```yaml +Type: System.DateTime +Parameter Sets: GetExpanded +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Fields +optional list of fields to return from query + +```yaml +Type: System.String[] +Parameter Sets: GetExpanded +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SearchAfter +Specific query to search after, see x-* response headers for next values + +```yaml +Type: System.String[] +Parameter Sets: GetExpanded +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SearchTermAnd +list of event terms. +If all terms match the event will be returned by the service. + +```yaml +Type: System.Collections.Hashtable +Parameter Sets: GetExpanded +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SearchTermOr +list of event terms. +If any term matches, the event will be returned by the service. + +```yaml +Type: System.Collections.Hashtable +Parameter Sets: GetExpanded +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Sort +ASC or DESC order for timestamp + +```yaml +Type: System.String +Parameter Sets: GetExpanded +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Body +EventQuery is the users' command to search our auth logs +To construct, see NOTES section for BODY properties and create a hash table. + +```yaml +Type: JumpCloud.SDK.DirectoryInsights.Models.IEventQuery +Parameter Sets: Get +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +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 + +### JumpCloud.SDK.DirectoryInsights.Models.IEventQuery +## OUTPUTS + +### System.Int64 +### System.String +## NOTES +COMPLEX PARAMETER PROPERTIES + +To create the parameters described below, construct a hash table containing the appropriate properties. +For information on hash tables, run Get-Help about_Hash_Tables. + +BODY \: EventQuery is the users' command to search our auth logs + Service \: service name to query. +Known services: systems,radius,sso,directory,ldap,all + StartTime \: query start time, UTC in RFC3339 format + \[EndTime \\]: optional query end time, UTC in RFC3339 format + \[Fields \\]: optional list of fields to return from query + \[Limit \\]: Max number of rows to return + \[SearchAfter \\]: Specific query to search after, see x-* response headers for next values + \[SearchTermAnd \\]: list of event terms. +If all terms match the event will be returned by the service. + \[(Any) \\]: This indicates any property can be added to this object. + \[SearchTermOr \\]: list of event terms. +If any term matches, the event will be returned by the service. + \[(Any) \\]: This indicates any property can be added to this object. + \[Sort \\]: ASC or DESC order for timestamp + +## RELATED LINKS + +[https://github.com/TheJumpCloud/jcapi-powershell/tree/master/SDKs/PowerShell/jumpcloud.sdk.directoryinsights/get-jcsdkeventcount](https://github.com/TheJumpCloud/jcapi-powershell/tree/master/SDKs/PowerShell/jumpcloud.sdk.directoryinsights/get-jcsdkeventcount) + diff --git a/PowerShell/JumpCloud Module/JumpCloud.psd1 b/PowerShell/JumpCloud Module/JumpCloud.psd1 index 45b930302..4ca2fac3a 100755 --- 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/9/2020 +# Generated on: 7/20/2020 # @{ @@ -12,7 +12,7 @@ RootModule = 'JumpCloud.psm1' # Version number of this module. -ModuleVersion = '1.17.4' +ModuleVersion = '1.17.5' # Supported PSEditions # CompatiblePSEditions = @() @@ -51,7 +51,9 @@ PowerShellVersion = '4.0' # ProcessorArchitecture = '' # Modules that must be imported into the global environment prior to importing this module -RequiredModules = @('JumpCloud.SDK.DirectoryInsights') +RequiredModules = @('JumpCloud.SDK.DirectoryInsights', + 'JumpCloud.SDK.V1', + 'JumpCloud.SDK.V2') # Assemblies that must be loaded prior to importing this module # RequiredAssemblies = @() @@ -74,8 +76,8 @@ FunctionsToExport = 'Add-JCAssociation', 'Add-JCCommandTarget', 'Add-JCSystemUser', 'Add-JCUserGroupMember', 'Connect-JCOnline', 'Copy-JCAssociation', 'Get-JCAssociation', 'Get-JCBackup', 'Get-JCCommand', 'Get-JCCommandResult', 'Get-JCCommandTarget', - 'Get-JCEvent', 'Get-JCGroup', 'Get-JCOrganization', 'Get-JCPolicy', - 'Get-JCPolicyResult', 'Get-JCPolicyTargetGroup', + 'Get-JCEvent', 'Get-JCEventCount', 'Get-JCGroup', 'Get-JCOrganization', + 'Get-JCPolicy', 'Get-JCPolicyResult', 'Get-JCPolicyTargetGroup', 'Get-JCPolicyTargetSystem', 'Get-JCRadiusReplyAttribute', 'Get-JCRadiusServer', 'Get-JCSystem', 'Get-JCSystemGroupMember', 'Get-JCSystemInsights', 'Get-JCSystemUser', 'Get-JCUser', diff --git a/PowerShell/JumpCloud Module/JumpCloud.psm1 b/PowerShell/JumpCloud Module/JumpCloud.psm1 index 4dbc3c4c8..5e8ffeb24 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.psm1 +++ b/PowerShell/JumpCloud Module/JumpCloud.psm1 @@ -1,14 +1,11 @@ # Load all functions from public and private folders $Public = @( Get-ChildItem -Path "$PSScriptRoot/Public/*.ps1" -Recurse ) $Private = @( Get-ChildItem -Path "$PSScriptRoot/Private/*.ps1" -Recurse) -Foreach ($Import in @($Public + $Private)) -{ - Try - { +Foreach ($Import in @($Public + $Private)) { + Try { . $Import.FullName } - Catch - { + Catch { Write-Error -Message "Failed to import function $($Import.FullName): $_" } } @@ -34,9 +31,10 @@ If ($PSVersionTable.PSEdition -eq 'Core') $PSDefaultParameterValues['Invoke-WebRequest:MaximumRetryCount'] = 5 $PSDefaultParameterValues['Invoke-WebRequest:RetryIntervalSec'] = 5 } -Else -{ - #Ignore SSL errors +Else { + #Ignore SSL errors / do not add policy if it exists + if (-Not [System.Net.ServicePointManager]::CertificatePolicy) + { Add-Type @" using System.Net; using System.Security.Cryptography.X509Certificates; @@ -48,7 +46,8 @@ Else } } "@ - [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy + [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy + } } # Set function aliases Set-Alias -Name:('New-JCAssociation') -Value:('Add-JCAssociation') diff --git a/PowerShell/JumpCloud Module/Public/DirectoryInsights/Get-JCEvent.ps1 b/PowerShell/JumpCloud Module/Public/DirectoryInsights/Get-JCEvent.ps1 index 56dbe635c..6b7a7b0ed 100644 --- a/PowerShell/JumpCloud Module/Public/DirectoryInsights/Get-JCEvent.ps1 +++ b/PowerShell/JumpCloud Module/Public/DirectoryInsights/Get-JCEvent.ps1 @@ -4,35 +4,35 @@ Query the API for Directory Insights events .Description Query the API for Directory Insights events .Example -PS C:\> (Get-JCEvent -Service:('all') -StartTime:((Get-date).AddDays(-30))) +PS C:\> Get-JCEvent -Service:('all') -StartTime:((Get-date).AddDays(-30)) Pull all event records from the last thirty days .Example -PS C:\> (Get-JCEvent -Service:('directory') -StartTime:((Get-date).AddHours(-1)) -Limit:('10')) +PS C:\> Get-JCEvent -Service:('directory') -StartTime:((Get-date).AddHours(-1)) -Limit:('10') 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))) +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"}) +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")}) +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"}) +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"}) +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"}) +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 @@ -44,9 +44,12 @@ JumpCloud.SDK.DirectoryInsights.Models.IPost200ApplicationJsonItemsItem System.String .Notes COMPLEX PARAMETER PROPERTIES + To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables. -EVENTQUERYBODY : EventQuery is the users' command to search our auth logs +BODY : EventQuery is the users' command to search our auth logs + Service : service name to query. Known services: systems,radius,sso,directory,ldap,all + StartTime : query start time, UTC in RFC3339 format [EndTime ]: optional query end time, UTC in RFC3339 format [Fields ]: optional list of fields to return from query [Limit ]: Max number of rows to return @@ -55,24 +58,27 @@ EVENTQUERYBODY : EventQuery is the users' command to search our aut [(Any) ]: This indicates any property can be added to this object. [SearchTermOr ]: list of event terms. If any term matches, the event will be returned by the service. [(Any) ]: This indicates any property can be added to this object. - [Service ]: service name to query. Known services: systems,radius,sso,directory,ldap,all [Sort ]: ASC or DESC order for timestamp - [StartTime ]: query start time, UTC in RFC3339 format .Link -https://github.com/TheJumpCloud/support/wiki/Get-JCEvent +https://github.com/TheJumpCloud/jcapi-powershell/tree/master/SDKs/PowerShell/JumpCloud.SDK.DirectoryInsights/docs/exports/Get-JcSdkEvent.md #> Function Get-JCEvent { - #Requires -Modules JumpCloud.SDK.DirectoryInsights [OutputType([JumpCloud.SDK.DirectoryInsights.Models.IPost200ApplicationJsonItemsItem], [System.String])] [CmdletBinding(DefaultParameterSetName='GetExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')] Param( - [Parameter(ParameterSetName='Get', Mandatory, ValueFromPipeline)] + [Parameter(ParameterSetName='GetExpanded', Mandatory)] [JumpCloud.SDK.DirectoryInsights.Category('Body')] - [JumpCloud.SDK.DirectoryInsights.Models.IEventQuery] - # EventQuery is the users' command to search our auth logs - # To construct, see NOTES section for EVENTQUERYBODY properties and create a hash table. - ${EventQueryBody}, + [System.String[]] + # service name to query. + # Known services: systems,radius,sso,directory,ldap,all + ${Service}, + + [Parameter(ParameterSetName='GetExpanded', Mandatory)] + [JumpCloud.SDK.DirectoryInsights.Category('Body')] + [System.DateTime] + # query start time, UTC in RFC3339 format + ${StartTime}, [Parameter(ParameterSetName='GetExpanded')] [JumpCloud.SDK.DirectoryInsights.Category('Body')] @@ -86,12 +92,6 @@ Function Get-JCEvent # optional list of fields to return from query ${Fields}, - [Parameter(ParameterSetName='GetExpanded')] - [JumpCloud.SDK.DirectoryInsights.Category('Body')] - [System.Int64] - # Max number of rows to return - ${Limit}, - [Parameter(ParameterSetName='GetExpanded')] [JumpCloud.SDK.DirectoryInsights.Category('Body')] [System.String[]] @@ -114,99 +114,30 @@ Function Get-JCEvent # If any term matches, the event will be returned by the service. ${SearchTermOr}, - [Parameter(ParameterSetName='GetExpanded')] - [JumpCloud.SDK.DirectoryInsights.Category('Body')] - [System.String[]] - # service name to query. - # Known services: systems,radius,sso,directory,ldap,all - ${Service}, - [Parameter(ParameterSetName='GetExpanded')] [JumpCloud.SDK.DirectoryInsights.Category('Body')] [System.String] # ASC or DESC order for timestamp ${Sort}, - [Parameter(ParameterSetName='GetExpanded')] + [Parameter(ParameterSetName='Get', Mandatory, ValueFromPipeline)] [JumpCloud.SDK.DirectoryInsights.Category('Body')] - [System.DateTime] - # query start time, UTC in RFC3339 format - ${StartTime}, - - [System.Boolean] - # Set to $true to return all results. - $Paginate = $true + [JumpCloud.SDK.DirectoryInsights.Models.IEventQuery] + # EventQuery is the users' command to search our auth logs + # To construct, see NOTES section for BODY properties and create a hash table. + ${Body} ) Begin { Connect-JCOnline -force | Out-Null $Results = @() - $PSBoundParameters.Add('HttpPipelineAppend', { - param($req, $callback, $next) - # call the next step in the Pipeline - $ResponseTask = $next.SendAsync($req, $callback) - $global:JCHttpRequest = $req - $global:JCHttpRequestContent = $req.Content.ReadAsStringAsync() - $global:JCHttpResponse = $ResponseTask - Return $ResponseTask - } - ) } Process { - If ($Paginate) - { - $PSBoundParameters.Remove('Paginate') | Out-Null - Do - { - $Result = Get-JcSdkEvent @PSBoundParameters - If (-not [System.String]::IsNullOrEmpty($Result)) - { - $XResultSearchAfter = ($JCHttpResponse.Result.Headers.GetValues('X-Search_after') | ConvertFrom-Json); - If ([System.String]::IsNullOrEmpty($PSBoundParameters.SearchAfter)) - { - If ([System.String]::IsNullOrEmpty($PSBoundParameters.EventQueryBody)) - { - $PSBoundParameters.Add('SearchAfter', $XResultSearchAfter) - } - Else - { - $PSBoundParameters.EventQueryBody.SearchAfter = $XResultSearchAfter - } - } - Else - { - $PSBoundParameters.SearchAfter = $XResultSearchAfter - } - $XResultCount = $JCHttpResponse.Result.Headers.GetValues('X-Result-Count') - $XLimit = $JCHttpResponse.Result.Headers.GetValues('X-Limit') - $Results += ($Result).ToJsonString() | ConvertFrom-Json; - } - Write-Debug ("ResultCount: $($XResultCount); Limit: $($XLimit); XResultSearchAfter: $($XResultSearchAfter); "); - Write-Debug ('HttpRequest: ' + $JCHttpRequest); - Write-Debug ('HttpRequestContent: ' + $JCHttpRequestContent.Result); - } - While ($XResultCount -eq $XLimit -and $Result) - } - Else - { - $PSBoundParameters.Remove('Paginate') | Out-Null - $Result = Get-JcSdkEvent @PSBoundParameters - Write-Debug ('HttpRequest: ' + $JCHttpRequest); - Write-Debug ('HttpRequestContent: ' + $JCHttpRequestContent.Result); - If (-not [System.String]::IsNullOrEmpty($Result)) - { - $Results += ($Result).ToJsonString() | ConvertFrom-Json; - } - } + $Results = JumpCloud.SDK.DirectoryInsights\Get-JcSdkEvent @PSBoundParameters } End { - # Clean up global variables - $GlobalVars = @('JCHttpRequest', 'JCHttpRequestContent', 'JCHttpResponse') - $GlobalVars | ForEach-Object { - If ((Get-Variable -Scope:('Global')).Where( { $_.Name -eq $_ })) { Remove-Variable -Name:($_) -Scope:('Global') } - } Return $Results } } diff --git a/PowerShell/JumpCloud Module/Public/DirectoryInsights/Get-JCEventCount.ps1 b/PowerShell/JumpCloud Module/Public/DirectoryInsights/Get-JCEventCount.ps1 new file mode 100644 index 000000000..b67738c71 --- /dev/null +++ b/PowerShell/JumpCloud Module/Public/DirectoryInsights/Get-JCEventCount.ps1 @@ -0,0 +1,127 @@ +<# +.Synopsis +Query the API for a count of matching events +.Description +Query the API for a count of matching events +.Example +PS C:\> Get-JCEventCount -Service:('all') -StartTime:((Get-date).AddDays(-30)) + +Pull all event records from a specified time and count the results +.Example +PS C:\> Get-JCEventCount -Service:('sso') -StartTime:('2020-04-14T00:00:00Z') + +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 + +.Inputs +JumpCloud.SDK.DirectoryInsights.Models.IEventQuery +.Outputs +System.Int64 +.Outputs +System.String +.Notes +COMPLEX PARAMETER PROPERTIES + +To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables. + +BODY : EventQuery is the users' command to search our auth logs + Service : service name to query. Known services: systems,radius,sso,directory,ldap,all + StartTime : query start time, UTC in RFC3339 format + [EndTime ]: optional query end time, UTC in RFC3339 format + [Fields ]: optional list of fields to return from query + [Limit ]: Max number of rows to return + [SearchAfter ]: Specific query to search after, see x-* response headers for next values + [SearchTermAnd ]: list of event terms. If all terms match the event will be returned by the service. + [(Any) ]: This indicates any property can be added to this object. + [SearchTermOr ]: list of event terms. If any term matches, the event will be returned by the service. + [(Any) ]: This indicates any property can be added to this object. + [Sort ]: ASC or DESC order for timestamp +.Link +https://github.com/TheJumpCloud/jcapi-powershell/tree/master/SDKs/PowerShell/JumpCloud.SDK.DirectoryInsights/docs/exports/Get-JcSdkEventCount.md +#> +Function Get-JCEventCount +{ + [OutputType([System.Int64], [System.String])] + [CmdletBinding(DefaultParameterSetName='GetExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')] + Param( + [Parameter(ParameterSetName='GetExpanded', Mandatory)] + [JumpCloud.SDK.DirectoryInsights.Category('Body')] + [System.String[]] + # service name to query. + # Known services: systems,radius,sso,directory,ldap,all + ${Service}, + + [Parameter(ParameterSetName='GetExpanded', Mandatory)] + [JumpCloud.SDK.DirectoryInsights.Category('Body')] + [System.DateTime] + # query start time, UTC in RFC3339 format + ${StartTime}, + + [Parameter(ParameterSetName='GetExpanded')] + [JumpCloud.SDK.DirectoryInsights.Category('Body')] + [System.DateTime] + # optional query end time, UTC in RFC3339 format + ${EndTime}, + + [Parameter(ParameterSetName='GetExpanded')] + [JumpCloud.SDK.DirectoryInsights.Category('Body')] + [System.String[]] + # optional list of fields to return from query + ${Fields}, + + [Parameter(ParameterSetName='GetExpanded')] + [JumpCloud.SDK.DirectoryInsights.Category('Body')] + [System.String[]] + # Specific query to search after, see x-* response headers for next values + ${SearchAfter}, + + [Parameter(ParameterSetName='GetExpanded')] + [JumpCloud.SDK.DirectoryInsights.Category('Body')] + [JumpCloud.SDK.DirectoryInsights.Runtime.Info(PossibleTypes=([JumpCloud.SDK.DirectoryInsights.Models.ISearchTermAnd]))] + [System.Collections.Hashtable] + # list of event terms. + # If all terms match the event will be returned by the service. + ${SearchTermAnd}, + + [Parameter(ParameterSetName='GetExpanded')] + [JumpCloud.SDK.DirectoryInsights.Category('Body')] + [JumpCloud.SDK.DirectoryInsights.Runtime.Info(PossibleTypes=([JumpCloud.SDK.DirectoryInsights.Models.ISearchTermOr]))] + [System.Collections.Hashtable] + # list of event terms. + # If any term matches, the event will be returned by the service. + ${SearchTermOr}, + + [Parameter(ParameterSetName='GetExpanded')] + [JumpCloud.SDK.DirectoryInsights.Category('Body')] + [System.String] + # ASC or DESC order for timestamp + ${Sort}, + + [Parameter(ParameterSetName='Get', Mandatory, ValueFromPipeline)] + [JumpCloud.SDK.DirectoryInsights.Category('Body')] + [JumpCloud.SDK.DirectoryInsights.Models.IEventQuery] + # EventQuery is the users' command to search our auth logs + # To construct, see NOTES section for BODY properties and create a hash table. + ${Body} + ) + Begin + { + Connect-JCOnline -force | Out-Null + $Results = @() + } + Process + { + $Results = JumpCloud.SDK.DirectoryInsights\Get-JcSdkEventCount @PSBoundParameters + } + End + { + Return $Results + } +} diff --git a/PowerShell/JumpCloud Module/Tests/ModuleValidation/PesterFiles.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/ModuleValidation/PesterFiles.Tests.ps1 index d93efa0dd..ff8d79f4f 100755 --- a/PowerShell/JumpCloud Module/Tests/ModuleValidation/PesterFiles.Tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/ModuleValidation/PesterFiles.Tests.ps1 @@ -16,7 +16,13 @@ Describe -Tag:('ModuleValidation') 'Pester Files Tests' { Test-Path -Path:($FilePath) | Should -Be $true } It ('Validating Pester test file has been populated for ""') -TestCases:(Get-PesterFilesTestCases) { - $FilePath | Should -FileContentMatch '.*?' + # $FilePath | Should -FileContentMatch '.*?' + $FileContent = Get-Content -Path:($FilePath) -Raw + If ([System.String]::IsNullOrEmpty($FileContent)) + { + Write-Host("##vso[task.logissue type=warning;]" + 'The test file "' + $FilePath + '" has not been populated.') + Write-Warning ('The test file "' + $FilePath + '" has not been populated.') + } } } } diff --git a/PowerShell/JumpCloud Module/Tests/Public/DirectoryInsights/Get-JCEvent.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/DirectoryInsights/Get-JCEvent.Tests.ps1 index c42d13eca..fdb79fd36 100644 --- a/PowerShell/JumpCloud Module/Tests/Public/DirectoryInsights/Get-JCEvent.Tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/DirectoryInsights/Get-JCEvent.Tests.ps1 @@ -6,26 +6,17 @@ Describe 'Get-JCEvent' -Tag:('JCEvent') { #> # Define parameters for functions $ParamHash = @{ - "StartTime" = (Get-Date).ToUniversalTime(); - "EndTime" = 'PlaceHolderDateTime'; + "StartTime" = (Get-Date).AddHours(-24).ToUniversalTime(); + "EndTime" = (Get-Date).ToUniversalTime(); "Service" = "all"; "Sort" = "DESC" - "Limit" = 2; "SearchTermAnd" = @{ "event_type" = "user_delete" } } - If ((Get-Command Get-JCEvent).Parameters.ContainsKey('Paginate')) - { - $ParamHash.Limit = ($ParamHash.Limit * 2) - } - Else - { - $ParamHash.Limit - } # Create event records for tests Connect-JCOnline -force | Out-Null - For ($i = 1; $i -le $ParamHash.Limit; $i++) + For ($i = 1; $i -le 4; $i++) { $UserName = 'JCSystemUserTest-{0}' -f $i Write-Host ("Creating add/delete records for: $UserName") @@ -45,47 +36,39 @@ Describe 'Get-JCEvent' -Tag:('JCEvent') { $EndTime = [DateTime]$ParamHash.EndTime } It 'GetExpanded' { - $eventTest = Get-JCEvent -Service:($ParamHash.Service) -StartTime:($ParamHash.StartTime) -EndTime:($ParamHash.EndTime) -Limit:($ParamHash.Limit) -Sort:($ParamHash.Sort) -SearchTermAnd:($ParamHash.SearchTermAnd) - If ([System.String]::IsNullOrEmpty($eventTest)) - { + $eventTest = Get-JCEvent -Service:($ParamHash.Service) -StartTime:($ParamHash.StartTime) -EndTime:($ParamHash.EndTime) -Sort:($ParamHash.Sort) -SearchTermAnd:($ParamHash.SearchTermAnd) + If ([System.String]::IsNullOrEmpty($eventTest)) { $eventTest | Should -Not -BeNullOrEmpty } - Else - { - $eventTest = ($eventTest) + Else { + # $eventTest = $eventTest $MostRecentRecord = ([System.DateTime]($eventTest | Select-Object -First 1).timestamp).ToUniversalTime() $OldestRecord = ([System.DateTime]($eventTest | Select-Object -Last 1).timestamp).ToUniversalTime() - # Limit - Test that results count matches parameter value - $eventTest.Count | Should -Be $ParamHash.Limit # Sort - Test that results come back in decending DateTime - $MostRecentRecord.Ticks | Should -BeGreaterThan $OldestRecord.Ticks + $MostRecentRecord | Should -BeGreaterThan $OldestRecord # EndTime - Test that results are not newer than EndTime parameter value - $MostRecentRecord.Ticks | Should -BeLessOrEqual $EndTime.Ticks + $MostRecentRecord | Should -BeLessOrEqual $ParamHash.EndTime # StartTime - Test that results are not older than StartTime parameter value - $OldestRecord.Ticks | Should -BeGreaterOrEqual $StartTime.Ticks + $OldestRecord | Should -BeGreaterOrEqual $ParamHash.StartTime # SearchTermAnd - Test that results matches parameter value ($eventTest.event_type | Select-Object -Unique) | Should -Be $ParamHash.SearchTermAnd.event_type } } It 'Get' { - $eventTest = Get-JCEvent -EventQueryBody:($ParamHash) - If ([System.String]::IsNullOrEmpty($eventTest)) - { + $eventTest = Get-JCEvent -Body:($ParamHash) + If ([System.String]::IsNullOrEmpty($eventTest)) { $eventTest | Should -Not -BeNullOrEmpty } - Else - { - $eventTest = ($eventTest) + Else { + # $eventTest = $eventTest $MostRecentRecord = ([System.DateTime]($eventTest | Select-Object -First 1).timestamp).ToUniversalTime() $OldestRecord = ([System.DateTime]($eventTest | Select-Object -Last 1).timestamp).ToUniversalTime() - # Limit - Test that results count matches parameter value - $eventTest.Count | Should -Be $ParamHash.Limit # Sort - Test that results come back in decending DateTime - $MostRecentRecord.Ticks | Should -BeGreaterThan $OldestRecord.Ticks + $MostRecentRecord | Should -BeGreaterThan $OldestRecord # EndTime - Test that results are not newer than EndTime parameter value - $MostRecentRecord.Ticks | Should -BeLessOrEqual $EndTime.Ticks + $MostRecentRecord | Should -BeLessOrEqual $ParamHash.EndTime # StartTime - Test that results are not older than StartTime parameter value - $OldestRecord.Ticks | Should -BeGreaterOrEqual $StartTime.Ticks + $OldestRecord | Should -BeGreaterOrEqual $ParamHash.StartTime # SearchTermAnd - Test that results matches parameter value ($eventTest.event_type | Select-Object -Unique) | Should -Be $ParamHash.SearchTermAnd.event_type } diff --git a/PowerShell/JumpCloud Module/Tests/Public/DirectoryInsights/Get-JCEventCount.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/DirectoryInsights/Get-JCEventCount.Tests.ps1 new file mode 100644 index 000000000..e69de29bb diff --git a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml index f452acd30..13e8a890e 100644 --- a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml +++ b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml @@ -3763,55 +3763,30 @@ Get-JCEvent - - EventQueryBody + + Service - EventQuery is the users' command to search our auth logs To construct, see NOTES section for EVENTQUERYBODY properties and create a hash table. + service name to query. Known services: systems,radius,sso,directory,ldap,all - JumpCloud.SDK.DirectoryInsights.Models.IEventQuery + System.String[] - JumpCloud.SDK.DirectoryInsights.Models.IEventQuery + System.String[] None - - Paginate - - Set to $true to return all results. - - System.Boolean - - System.Boolean - - - True - - - WhatIf - - Shows what would happen if the cmdlet runs. The cmdlet is not run. - - - System.Management.Automation.SwitchParameter - - - False - - - Confirm + + StartTime - Prompts you for confirmation before running the cmdlet. + query start time, UTC in RFC3339 format + System.DateTime - System.Management.Automation.SwitchParameter + System.DateTime - False + None - - - Get-JCEvent EndTime @@ -3836,18 +3811,6 @@ None - - Limit - - Max number of rows to return - - System.Int64 - - System.Int64 - - - 0 - SearchAfter @@ -3885,52 +3848,53 @@ None - Service + Sort - service name to query. Known services: systems,radius,sso,directory,ldap,all + ASC or DESC order for timestamp - System.String[] + System.String - System.String[] + System.String None - - Sort + + WhatIf - ASC or DESC order for timestamp + Shows what would happen if the cmdlet runs. The cmdlet is not run. - System.String - System.String + System.Management.Automation.SwitchParameter - None + False - - StartTime + + Confirm - query start time, UTC in RFC3339 format + Prompts you for confirmation before running the cmdlet. - System.DateTime - System.DateTime + System.Management.Automation.SwitchParameter - None + False - - Paginate + + + Get-JCEvent + + Body - Set to $true to return all results. + EventQuery is the users' command to search our auth logs To construct, see NOTES section for BODY properties and create a hash table. - System.Boolean + JumpCloud.SDK.DirectoryInsights.Models.IEventQuery - System.Boolean + JumpCloud.SDK.DirectoryInsights.Models.IEventQuery - True + None WhatIf @@ -3957,14 +3921,26 @@ - - EventQueryBody + + Service + + service name to query. Known services: systems,radius,sso,directory,ldap,all + + System.String[] + + System.String[] + + + None + + + StartTime - EventQuery is the users' command to search our auth logs To construct, see NOTES section for EVENTQUERYBODY properties and create a hash table. + query start time, UTC in RFC3339 format - JumpCloud.SDK.DirectoryInsights.Models.IEventQuery + System.DateTime - JumpCloud.SDK.DirectoryInsights.Models.IEventQuery + System.DateTime None @@ -3993,18 +3969,6 @@ None - - Limit - - Max number of rows to return - - System.Int64 - - System.Int64 - - - 0 - SearchAfter @@ -4041,18 +4005,6 @@ None - - Service - - service name to query. Known services: systems,radius,sso,directory,ldap,all - - System.String[] - - System.String[] - - - None - Sort @@ -4065,30 +4017,18 @@ None - - StartTime + + Body - query start time, UTC in RFC3339 format + EventQuery is the users' command to search our auth logs To construct, see NOTES section for BODY properties and create a hash table. - System.DateTime + JumpCloud.SDK.DirectoryInsights.Models.IEventQuery - System.DateTime + JumpCloud.SDK.DirectoryInsights.Models.IEventQuery None - - Paginate - - Set to $true to return all results. - - System.Boolean - - System.Boolean - - - True - WhatIf @@ -4213,6 +4153,388 @@ + + + Get-JCEventCount + Get + JCEventCount + + Query the API for a count of matching events + + + + Query the API for a count of matching events + + + + Get-JCEventCount + + Service + + service name to query. Known services: systems,radius,sso,directory,ldap,all + + System.String[] + + System.String[] + + + None + + + StartTime + + query start time, UTC in RFC3339 format + + System.DateTime + + System.DateTime + + + None + + + EndTime + + optional query end time, UTC in RFC3339 format + + System.DateTime + + System.DateTime + + + None + + + Fields + + optional list of fields to return from query + + System.String[] + + System.String[] + + + None + + + SearchAfter + + Specific query to search after, see x-* response headers for next values + + System.String[] + + System.String[] + + + None + + + SearchTermAnd + + list of event terms. If all terms match the event will be returned by the service. + + System.Collections.Hashtable + + System.Collections.Hashtable + + + None + + + SearchTermOr + + list of event terms. If any term matches, the event will be returned by the service. + + System.Collections.Hashtable + + System.Collections.Hashtable + + + None + + + Sort + + ASC or DESC order for timestamp + + System.String + + System.String + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + System.Management.Automation.SwitchParameter + + + False + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + System.Management.Automation.SwitchParameter + + + False + + + + Get-JCEventCount + + Body + + EventQuery is the users' command to search our auth logs To construct, see NOTES section for BODY properties and create a hash table. + + JumpCloud.SDK.DirectoryInsights.Models.IEventQuery + + JumpCloud.SDK.DirectoryInsights.Models.IEventQuery + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + System.Management.Automation.SwitchParameter + + + False + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + System.Management.Automation.SwitchParameter + + + False + + + + + + Service + + service name to query. Known services: systems,radius,sso,directory,ldap,all + + System.String[] + + System.String[] + + + None + + + StartTime + + query start time, UTC in RFC3339 format + + System.DateTime + + System.DateTime + + + None + + + EndTime + + optional query end time, UTC in RFC3339 format + + System.DateTime + + System.DateTime + + + None + + + Fields + + optional list of fields to return from query + + System.String[] + + System.String[] + + + None + + + SearchAfter + + Specific query to search after, see x-* response headers for next values + + System.String[] + + System.String[] + + + None + + + SearchTermAnd + + list of event terms. If all terms match the event will be returned by the service. + + System.Collections.Hashtable + + System.Collections.Hashtable + + + None + + + SearchTermOr + + list of event terms. If any term matches, the event will be returned by the service. + + System.Collections.Hashtable + + System.Collections.Hashtable + + + None + + + Sort + + ASC or DESC order for timestamp + + System.String + + System.String + + + None + + + Body + + EventQuery is the users' command to search our auth logs To construct, see NOTES section for BODY properties and create a hash table. + + JumpCloud.SDK.DirectoryInsights.Models.IEventQuery + + JumpCloud.SDK.DirectoryInsights.Models.IEventQuery + + + None + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + System.Management.Automation.SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + System.Management.Automation.SwitchParameter + + System.Management.Automation.SwitchParameter + + + False + + + + + + JumpCloud.SDK.DirectoryInsights.Models.IEventQuery + + + + + + + + + + System.Int64 + + + + + + + + System.String + + + + + + + + + COMPLEX PARAMETER PROPERTIES + To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables. + BODY <IEventQuery>: EventQuery is the users' command to search our auth logs Service <String[]>: service name to query. Known services: systems,radius,sso,directory,ldap,all StartTime <DateTime>: query start time, UTC in RFC3339 format [EndTime <DateTime?>]: optional query end time, UTC in RFC3339 format [Fields <String[]>]: optional list of fields to return from query [Limit <Int64?>]: Max number of rows to return [SearchAfter <String[]>]: Specific query to search after, see x-* response headers for next values [SearchTermAnd <ISearchTermAnd>]: list of event terms. If all terms match the event will be returned by the service. [(Any) <Object>]: This indicates any property can be added to this object. [SearchTermOr <ISearchTermOr>]: list of event terms. If any term matches, the event will be returned by the service. [(Any) <Object>]: This indicates any property can be added to this object. [Sort <String>]: ASC or DESC order for timestamp + + + + + -------------------------- EXAMPLE 1 -------------------------- + Get-JCEventCount -Service:('all') -StartTime:((Get-date).AddDays(-30)) + + Pull all event records from a specified time and count the results + + + + -------------------------- EXAMPLE 2 -------------------------- + Get-JCEventCount -Service:('sso') -StartTime:('2020-04-14T00:00:00Z') + + Pull all SSO event records from a specified time and count the results + + + + -------------------------- EXAMPLE 3 -------------------------- + 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 4 -------------------------- + Get-JCEventCount -Service:('directory') -StartTime:((Get-date).AddDays(-30)) -searchTermAnd:@{"event_type" = "group_create"} + + Get only group_create event counts the last thirty days + + + + + + Online Version: + https://github.com/TheJumpCloud/support/wiki/Get-JCEventCount + + + https://github.com/TheJumpCloud/jcapi-powershell/tree/master/SDKs/PowerShell/jumpcloud.sdk.directoryinsights/get-jcsdkeventcount + https://github.com/TheJumpCloud/jcapi-powershell/tree/master/SDKs/PowerShell/jumpcloud.sdk.directoryinsights/get-jcsdkeventcount + + + Get-JCGroup diff --git a/PowerShell/ModuleBanner.md b/PowerShell/ModuleBanner.md index 03228d400..9e8656789 100755 --- a/PowerShell/ModuleBanner.md +++ b/PowerShell/ModuleBanner.md @@ -1,7 +1,7 @@ #### Latest Version ``` -1.17.4 +1.17.5 ``` #### Banner Current diff --git a/PowerShell/ModuleChangelog.md b/PowerShell/ModuleChangelog.md index 8eedb03e4..dc6973231 100644 --- a/PowerShell/ModuleChangelog.md +++ b/PowerShell/ModuleChangelog.md @@ -1,6 +1,6 @@ -## 1.17.4 +## 1.17.5 -Release Date: July 9, 2020 +Release Date: July 20, 2020 #### RELEASE NOTES @@ -8,13 +8,16 @@ Use Get-JCSystemInsight to query additional System Insights tables. #### FEATURES +Updated Get-JCEvent. +New function Get-JCEventCount. +Remove Depreciated SystemInsights Registry Table. + #### IMPROVEMENTS #### BUG FIXES -Fix for Update-JCModule Pester tests - -Remove Depreciated SystemInsights Registry Table +Fix for windows PowerShell Update-JCModule function. +Fix for pipeline to specify manual version of module ## 1.17.3