Skip to content

Commit

Permalink
Merge pull request #633 from TheJumpCloud/CUT-3883_NewJCReports
Browse files Browse the repository at this point in the history
CUT-3883/CUT-3884: JCReport Functions
  • Loading branch information
gweinjc authored Jan 2, 2025
2 parents 04e14b9 + 5ba092b commit 9ab8c31
Show file tree
Hide file tree
Showing 13 changed files with 953 additions and 121 deletions.
50 changes: 31 additions & 19 deletions PowerShell/Deploy/SdkSync/jcapiToSupportSync.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ $ApprovedFunctions = [Ordered]@{
Name = 'Get-JcSdkEventCount';
Destination = '/Public/DirectoryInsights';
}
# [PSCustomObject]@{
# Name = 'Get-JcSdkReport';
# Destination = '/Public/Reports';
# },
# [PSCustomObject]@{
# Name = 'New-JcSdkReport';
# Destination = '/Public/Reports';
# }
);
# 'JumpCloud.SDK.V2' = @(
#'JumpCloud.SDK.V2' = @(
# [PSCustomObject]@{
# Name = 'Get-JcSdkAppleMdm';
# Destination = '/Public/AppleMdm';
Expand Down Expand Up @@ -60,7 +68,7 @@ $ApprovedFunctions = [Ordered]@{
# Name = 'Get-JcSdkAppleMdmEnrollmentProfile';
# Destination = '/Public/AppleMdm';
# }
# )
#)
}
$SdkPrefix = 'JcSdk'
$JumpCloudModulePrefix = 'JC'
Expand Down Expand Up @@ -136,6 +144,11 @@ If (-not [System.String]::IsNullOrEmpty($Modules)) {
$Params = $FunctionContent | Select-String -Pattern:([regex]'(?s)( \[Parameter)(.*?)(\})') -AllMatches
$ParameterContent = ($Params.Matches.Value | Where-Object { $_ -notlike '*DontShow*' -and $_ -notlike '${Limit}' -and $_ -notlike '*${Skip}*' })

# Check if there is only one parameter
if ($ParameterContent -is [string]) {
$ParameterContent = @($ParameterContent)
}

for ($i = 0; $i -lt $ParameterContent.Count; $i++) {
if ($i -ne ($ParameterContent.Count - 1 )) {
$ParameterContent[$i] = $($ParameterContent[$i].Replace('}', '},'))
Expand Down Expand Up @@ -175,10 +188,9 @@ If (-not [System.String]::IsNullOrEmpty($Modules)) {
# $EndContent = @()
# Build "Begin" block

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, $BeginContent, $ProcessContent, $EndContent
$NewScript = @"
# Build "Function"
# $NewScript = $FunctionTemplate -f $PSScriptInfo, $NewCommandName, $CmdletBinding, $ParameterContent, $BeginContent, $ProcessContent, $EndContent
$NewScript = @"
$PSScriptInfo
Function $NewCommandName {
$($OutputType)
Expand All @@ -198,20 +210,20 @@ $paramString
}
}
"@
# $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
Write-Host ("[STATUS] Writing File: $OutputPath/$NewCommandName") -BackgroundColor:('Black') -ForegroundColor:('Magenta')
$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
}
# $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
Write-Host ("[STATUS] Writing File: $OutputPath/$NewCommandName") -BackgroundColor:('Black') -ForegroundColor:('Magenta')
$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
Expand Down
4 changes: 2 additions & 2 deletions PowerShell/JumpCloud Module/Docs/Connect-JCOnline.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The Connect-JCOnline function sets the global variable $JCAPIKEY
## SYNTAX

```
Connect-JCOnline [-force] [[-JumpCloudApiKey] <String>]
Connect-JCOnline [-force] [-JumpCloudApiKey] <String>
[[-JumpCloudOrgId] <String>] [[-JCEnvironment] <String>] [<CommonParameters>]
```

Expand Down Expand Up @@ -88,7 +88,7 @@ Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName)
Expand Down
121 changes: 121 additions & 0 deletions PowerShell/JumpCloud Module/Docs/Get-JCReport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
external help file: JumpCloud-help.xml
Module Name: JumpCloud
online version: https://github.com/TheJumpCloud/support/wiki/
schema: 2.0.0
---

# Get-JCReport

## SYNOPSIS
Ordered list of report metadata

## SYNTAX

### List (Default)
```
Get-JCReport [-Sort <Sort>] [<CommonParameters>]
```

### Report
```
Get-JCReport [-Sort <Sort>] -ReportID <String> -Type <String>
[<CommonParameters>]
```

## DESCRIPTION
Ordered list of report metadata

## EXAMPLES

### EXAMPLE 1
```
Get-JCReport
```

Returns a list of all available reports

### EXAMPLE 2
```
Get-JCReport -Sort 'CREATED_AT'
```

Returns a list of all available reports, sorted by the most recently created report

### EXAMPLE 3
```
$lastReport = Get-JCReport -Sort 'CREATED_AT' | Select -First 1
$reportContent = Get-JCReport -reportID $lastReport.id -type 'json'
```

Returns the report's content in JSON format from the last generated report

### EXAMPLE 4
```
$lastReport = Get-JCReport -Sort 'CREATED_AT' | Select -First 1
$reportContent = Get-JCReport -reportID $lastReport.id -type 'csv'
```

Returns the report's content in CSV format from the last generated report

## PARAMETERS

### -ReportID
ID of the Report request.

```yaml
Type: System.String
Parameter Sets: Report
Aliases: id

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Sort
Sort type and direction.
Default sort is descending, prefix with - to sort ascending.
```yaml
Type: JumpCloud.SDK.DirectoryInsights.Support.Sort
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Type
Output type of the report content, either CSV or JSON
```yaml
Type: System.String
Parameter Sets: Report
Aliases:

Required: True
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
## OUTPUTS
### JumpCloud.SDK.DirectoryInsights.Models.IGet200ApplicationJsonItemsItem
## NOTES
## RELATED LINKS
[https://github.com/TheJumpCloud/jcapi-powershell/tree/master/SDKs/PowerShell/JumpCloud.SDK.DirectoryInsights/docs/exports/Get-JcSdkReport.md](https://github.com/TheJumpCloud/jcapi-powershell/tree/master/SDKs/PowerShell/JumpCloud.SDK.DirectoryInsights/docs/exports/Get-JcSdkReport.md)
8 changes: 7 additions & 1 deletion PowerShell/JumpCloud Module/Docs/JumpCloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module Name: JumpCloud
Module Guid: 31c023d1-a901-48c4-90a3-082f91b31646
Download Help Link: https://github.com/TheJumpCloud/support/wiki
Help Version: 2.16.0
Help Version: 2.17.0
Locale: en-Us
---

Expand Down Expand Up @@ -110,6 +110,9 @@ Returns the Radius reply attributes associated with a JumpCloud user group.
### [Get-JCRadiusServer](Get-JCRadiusServer.md)
Return JumpCloud radius server information.

### [Get-JCReport](Get-JCReport.md)
Ordered list of report metadata

### [Get-JCScheduledUserstate](Get-JCScheduledUserstate.md)
Returns scheduled userstate changes by state or returns a user's scheduled userstate changes

Expand Down Expand Up @@ -181,6 +184,9 @@ This endpoint allows you to create a new Policy Group.
### [New-JCRadiusServer](New-JCRadiusServer.md)
Creates a JumpCloud radius server.

### [New-JCReport](New-JCReport.md)
Request a JumpCloud report to be generated asynchronously

### [New-JCSystemGroup](New-JCSystemGroup.md)
Creates a JumpCloud System Group

Expand Down
130 changes: 130 additions & 0 deletions PowerShell/JumpCloud Module/Docs/New-JCReport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
external help file: JumpCloud-help.xml
Module Name: JumpCloud
online version: https://github.com/TheJumpCloud/support/wiki/
schema: 2.0.0
---

# New-JCReport

## SYNOPSIS
Request a JumpCloud report to be generated asynchronously

## SYNTAX

### Create (Default)
```
New-JCReport -ReportType <ReportType1> [-WhatIf] [-Confirm]
[<CommonParameters>]
```

### CreateViaIdentity
```
New-JCReport -InputObject <IDirectoryInsightsApiIdentity> [-WhatIf]
[-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Request a JumpCloud report to be generated asynchronously

## EXAMPLES

### EXAMPLE 1
```
New-JCReport -ReportType 'users-to-sso-applications'
```

Queues creation of an user-to-sso-application report

### EXAMPLE 2
```
New-JCReport -ReportType 'users-to-devices'
```

Queues creation of an users-to-devices report

## PARAMETERS

### -InputObject
Identity Parameter
To construct, see NOTES section for INPUTOBJECT properties and create a hash table.

```yaml
Type: JumpCloud.SDK.DirectoryInsights.Models.IDirectoryInsightsApiIdentity
Parameter Sets: CreateViaIdentity
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```
### -ReportType
Report Type
```yaml
Type: JumpCloud.SDK.DirectoryInsights.Support.ReportType1
Parameter Sets: Create
Aliases:

Required: True
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
```
### -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
```
### 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.IDirectoryInsightsApiIdentity
## OUTPUTS
### JumpCloud.SDK.DirectoryInsights.Models.IPathsE6Q3GdReportsReportTypePostResponses202ContentApplicationJsonSchema
## 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.
INPUTOBJECT \<IDirectoryInsightsApiIdentity\>: Identity Parameter
\[ReportType \<ReportType1?\>\]: Report Type
## RELATED LINKS
[https://github.com/TheJumpCloud/jcapi-powershell/tree/master/SDKs/PowerShell/JumpCloud.SDK.DirectoryInsights/docs/exports/New-JcSdkReport.md](https://github.com/TheJumpCloud/jcapi-powershell/tree/master/SDKs/PowerShell/JumpCloud.SDK.DirectoryInsights/docs/exports/New-JcSdkReport.md)
Loading

0 comments on commit 9ab8c31

Please sign in to comment.