diff --git a/PowerShell/Deploy/Build-HelpFiles.ps1 b/PowerShell/Deploy/Build-HelpFiles.ps1 new file mode 100755 index 000000000..c11302aed --- /dev/null +++ b/PowerShell/Deploy/Build-HelpFiles.ps1 @@ -0,0 +1,65 @@ +. ($PSScriptRoot + '/' + 'Get-Config.ps1') +########################################################################### +Write-Host ('[status]Importing current module: ' + $ModuleName) +Import-Module ($FilePath_psd1) -Force +Write-Host ('[status]Installing module: PlatyPS') +Install-Module -Name:('PlatyPS') -Force -Scope:('CurrentUser') +Write-Host ('[status]Creating/Updating help files') +$Functions_Public | ForEach-Object { + $FunctionName = $_.BaseName + $FilePath_Md = $FolderPath_Docs + '/' + $FunctionName + '.md' + If (Test-Path -Path:($FilePath_Md)) + { + # Write-Host ('Updating: ' + $FunctionName + '.md') + Update-MarkdownHelp -Path:($FilePath_Md) -Force -ExcludeDontShow -UpdateInputOutput + } + Else + { + # Write-Host ('Creating: ' + $FunctionName + '.md') + New-MarkdownHelp -Command:($FunctionName) -OutputFolder:($FolderPath_Docs) -Force -ExcludeDontShow -OnlineVersionUrl:($GitHubWikiUrl + $FunctionName) + } +} +# Create new ExternalHelp file. +Write-Host ('[status]Creating new external help file') +New-ExternalHelp -Path:($FolderPath_Docs) -OutputPath:($FolderPath_enUS) -Force + +# Create online versions of the help files in the support.wiki +# Update docs with links to the online docs for 'Get-Help -online' commands + +# ##TODO +# ### Add step check out support wiki +# $PathToSupportWikiRepo = '' +# $SupportRepoDocs = $PSScriptRoot + '/Docs' +# $SupportWiki = $PathToSupportWikiRepo + '/support.wiki' +# $Docs = Get-ChildItem -Path:($SupportRepoDocs + '/*.md') -Recurse +# ForEach ($Doc In $Docs) +# { +# $DocName = $Doc.Name +# $DocFullName = $Doc.FullName +# $SupportWikiDocFullName = $SupportWiki + '/' + $DocName +# $DocContent = Get-Content -Path:($DocFullName) +# If (Test-Path -Path:($SupportWikiDocFullName)) +# { +# $SupportWikiDocContent = Get-Content -Path:($SupportWikiDocFullName) +# $Diffs = Compare-Object -ReferenceObject:($DocContent) -DifferenceObject:($SupportWikiDocContent) +# If ($Diffs) +# { +# Write-Warning -Message:('Diffs found in: ' + $DocName) +# # are you sure you want to continue? +# } +# } +# Else +# { +# Write-Warning -Message:('Creating new file: ' + $DocName) +# } +# $NewDocContent = If (($DocContent | Select-Object -First 1) -eq '---') +# { +# $DocContent | Select-Object -Skip:(7) +# } +# Else +# { +# $DocContent +# } +# Set-Content -Path:($SupportWikiDocFullName) -Value:($NewDocContent) -Force +# } +# ### Add step check in changes to support wiki \ No newline at end of file diff --git a/PowerShell/Deploy/Build-Module.ps1 b/PowerShell/Deploy/Build-Module.ps1 new file mode 100755 index 000000000..903361e0d --- /dev/null +++ b/PowerShell/Deploy/Build-Module.ps1 @@ -0,0 +1,32 @@ +. ($PSScriptRoot + '/' + 'Get-Config.ps1') +# Region Checking PowerShell Gallery module version +Write-Host ('[status]Check PowerShell Gallery for module version info') +$PSGalleryInfo = Get-PSGalleryModuleVersion -Name:($ModuleName) -ReleaseType:($RELEASETYPE) #('Major', 'Minor', 'Patch') +$ModuleVersion = $PSGalleryInfo.NextVersion +Write-Host ('[status]PowerShell Gallery Name:' + $PSGalleryInfo.Name + ';CurrentVersion:' + $PSGalleryInfo.Version + '; NextVersion:' + $ModuleVersion ) +# EndRegion Checking PowerShell Gallery module version +# Region Building New-JCModuleManifest +Write-Host ('[status]Building New-JCModuleManifest') +New-JCModuleManifest -Path:($FilePath_psd1) ` + -FunctionsToExport:($Functions_Public.BaseName | Sort-Object) ` + -RootModule:((Get-Item -Path:($FilePath_psm1)).Name) ` + -ModuleVersion:($ModuleVersion) +# EndRegion Building New-JCModuleManifest +# Region Updating module banner +Write-Host ('[status]Updating module banner: "' + $FilePath_ModuleBanner + '"') +$ModuleBanner = Get-Content -Path:($FilePath_ModuleBanner) +$NewModuleBannerRecord = New-ModuleBanner -LatestVersion:($ModuleVersion) -BannerCurrent:('{{Fill in the Banner Current}}') -BannerOld:('{{Fill in the Banner Old}}') +If (!(($ModuleBanner | Select-Object -Index 3) -match $ModuleVersion)) +{ + $NewModuleBannerRecord.Trim() | Set-Content -Path:($FilePath_ModuleBanner) -Force +} +# EndRegion Updating module banner +# Region Updating module change log +Write-Host ('[status]Updating module change log: "' + $FilePath_ModuleChangelog + '"') +$ModuleChangelog = Get-Content -Path:($FilePath_ModuleChangelog) +$NewModuleChangelogRecord = New-ModuleChangelog -LatestVersion:($ModuleVersion) -ReleaseNotes:('{{Fill in the Release Notes}}') -Features:('{{Fill in the Features}}') -Improvements:('{{Fill in the Improvements}}') -BugFixes('{{Fill in the Bug Fixes}}') +If (!(($ModuleChangelog | Select-Object -First 1) -match $ModuleVersion)) +{ + ($NewModuleChangelogRecord + ($ModuleChangelog | Out-String)).Trim() | Set-Content -Path:($FilePath_ModuleChangelog) -Force +} +# EndRegion Updating module change log \ No newline at end of file diff --git a/PowerShell/Deploy/Build-PesterTestFiles.ps1 b/PowerShell/Deploy/Build-PesterTestFiles.ps1 new file mode 100755 index 000000000..e7f5a4073 --- /dev/null +++ b/PowerShell/Deploy/Build-PesterTestFiles.ps1 @@ -0,0 +1,16 @@ +. ($PSScriptRoot + '/' + 'Get-Config.ps1') +########################################################################### +Write-Host ('[status]Creating files for Pester tests') +$Files = $Functions_Public + $Functions_Private +Foreach ($File in $Files) +{ + $NewDirectory = ([string]$File.Directory).Replace($ModuleFolderName, $ModuleFolderName + '/' + $FolderName_Tests) + $NewName = $File.BaseName + '.Tests' + $File.Extension + $NewFullName = $NewDirectory + '/' + $NewName + If ( !( Test-Path -Path:($NewFullName) )) + { + New-FolderRecursive -Path:($NewFullName) + Write-Host ('[status]Create test files for new function') + New-Item -ItemType:('File') -Path:($NewFullName) -Force + } +} diff --git a/PowerShell/Deploy/Build-WikiPages.ps1 b/PowerShell/Deploy/Build-WikiPages.ps1 new file mode 100755 index 000000000..476f1544d --- /dev/null +++ b/PowerShell/Deploy/Build-WikiPages.ps1 @@ -0,0 +1,44 @@ +. ($PSScriptRoot + '/' + 'Get-Config.ps1') +########################################################################### +$CurrentLocation = Get-Location +Set-Location -Path:($StagingDirectory) +Invoke-GitClone -Repo:($GitSourceRepoWiki) + +### Add step check out support wiki +# $PathToSupportWikiRepo = '' +# $SupportRepoDocs = $PSScriptRoot + '/Docs' +# $SupportWiki = $PathToSupportWikiRepo + '/support.wiki' +# $Docs = Get-ChildItem -Path:($SupportRepoDocs + '/*.md') -Recurse +# ForEach ($Doc In $Docs) +# { +# $DocName = $Doc.Name +# $DocFullName = $Doc.FullName +# $SupportWikiDocFullName = $SupportWiki + '/' + $DocName +# $DocContent = Get-Content -Path:($DocFullName) +# If (Test-Path -Path:($SupportWikiDocFullName)) +# { +# $SupportWikiDocContent = Get-Content -Path:($SupportWikiDocFullName) +# $Diffs = Compare-Object -ReferenceObject:($DocContent) -DifferenceObject:($SupportWikiDocContent) +# If ($Diffs) +# { +# Write-Warning -Message:('Diffs found in: ' + $DocName) +# # are you sure you want to continue? +# } +# } +# Else +# { +# Write-Warning -Message:('Creating new file: ' + $DocName) +# } +# $NewDocContent = If (($DocContent | Select-Object -First 1) -eq '---') +# { +# $DocContent | Select-Object -Skip:(7) +# } +# Else +# { +# $DocContent +# } +# Set-Content -Path:($SupportWikiDocFullName) -Value:($NewDocContent) -Force +# } +# ### Add step check in changes to support wiki + +Set-Location -Path:($CurrentLocation) \ No newline at end of file diff --git a/PowerShell/Deploy/Execute-GitCommit.ps1 b/PowerShell/Deploy/Execute-GitCommit.ps1 new file mode 100755 index 000000000..b4cdca9a3 --- /dev/null +++ b/PowerShell/Deploy/Execute-GitCommit.ps1 @@ -0,0 +1,4 @@ +. ($PSScriptRoot + '/' + 'Get-Config.ps1') +########################################################################### +Write-Host ('[status]Commit changes to:' + $GitSourceBranch + ';') +Invoke-GitCommit -BranchName:($GitSourceBranch) \ No newline at end of file diff --git a/PowerShell/Deploy/Functions/Create-ModuleManifest.ps1 b/PowerShell/Deploy/Functions/Create-ModuleManifest.ps1 new file mode 100755 index 000000000..4cadaf75d --- /dev/null +++ b/PowerShell/Deploy/Functions/Create-ModuleManifest.ps1 @@ -0,0 +1,115 @@ +Function New-JCModuleManifest +{ + [cmdletbinding(SupportsShouldProcess = $True)] + Param() + DynamicParam + { + $Params = @() + $NewModuleManifestParameterSets = (Get-Command -Name:('New-ModuleManifest')).ParameterSets + ForEach ($NewModuleManifestParameterSet In $NewModuleManifestParameterSets) + { + ForEach ($NewModuleManifestParam In $NewModuleManifestParameterSet.Parameters) + { + If ($NewModuleManifestParam.Name -notin @([System.Management.Automation.PSCmdlet]::CommonParameters + [System.Management.Automation.PSCmdlet]::OptionalCommonParameters)) + { + $Params += @{ + 'ParameterSets' = $NewModuleManifestParameterSet.Name; + 'Name' = $NewModuleManifestParam.Name; + 'Type' = $NewModuleManifestParam.ParameterType.FullName; + 'Mandatory' = $NewModuleManifestParam.IsMandatory; + 'Position' = $NewModuleManifestParam.Position; + 'ValueFromPipeline' = $NewModuleManifestParam.ValueFromPipeline; + 'ValueFromPipelineByPropertyName' = $NewModuleManifestParam.ValueFromPipelineByPropertyName; + 'ValueFromRemainingArguments' = $NewModuleManifestParam.ValueFromRemainingArguments; + # 'HelpMessage' = $NewModuleManifestParam.HelpMessage; + 'Alias' = $NewModuleManifestParam.Aliases; + # 'DontShow' = ''; + # 'ValidateNotNull' = ''; + # 'ValidateNotNullOrEmpty' = ''; + # 'AllowEmptyString' = ''; + # 'AllowNull' = ''; + # 'AllowEmptyCollection' = ''; + # 'ValidateScript' = ''; + # 'ValidateSet' = ''; + # 'ValidateRange' = ''; + # 'ValidateCount' = ''; + # 'ValidateLength' = ''; + # 'ValidatePattern' = ''; + # 'RuntimeParameterDictionary' = ''; + } + } + } + } + $Params | ForEach-Object { + New-Object PSObject -Property $_ + } | New-DynamicParameter + } + Begin + { + # Create new variables for script + $PsBoundParameters.GetEnumerator() | ForEach-Object { Set-Variable -Name:($_.Key) -Value:($_.Value) -Force } + Write-Debug ('[CallFunction]' + $MyInvocation.MyCommand.Name + ' ' + ($PsBoundParameters.GetEnumerator() | Sort-Object Key | ForEach-Object { ('-' + $_.Key + ":('" + ($_.Value -join "','") + "')").Replace("'True'", '$True').Replace("'False'", '$False') }) ) + If ($PSCmdlet.ParameterSetName -ne '__AllParameterSets') { Write-Verbose ('[ParameterSet]' + $MyInvocation.MyCommand.Name + ':' + $PSCmdlet.ParameterSetName) } + $CurrentErrorActionPreference = $ErrorActionPreference + $ErrorActionPreference = 'Stop' + } + Process + { + # Create hash table to store variables + $FunctionParameters = [ordered]@{ } + If (Test-Path -Path:($Path)) + { + $FilePath_psd1 = Get-Item -Path:($Path) + $CurrentModuleManifest = Import-LocalizedData -BaseDirectory:($FilePath_psd1.DirectoryName) -FileName:($FilePath_psd1.BaseName) + # Add input parameters from function in to hash table and filter out unnecessary parameters + $CurrentModuleManifest.GetEnumerator() | ForEach-Object { $FunctionParameters.Add($_.Key, $_.Value) | Out-Null } + $PrivateDataPSData = $CurrentModuleManifest['PrivateData']['PSData'] + # New-ModuleManifest parameters that come from previous ModuleManifest PrivateData + $PrivateDataPSData.GetEnumerator() | ForEach-Object { + If ($FunctionParameters.Contains($_.Key)) + { + $FunctionParameters[$_.Key] = $_.Value + } + Else + { + $FunctionParameters.Add($_.Key, $_.Value) | Out-Null + } + } + # Remove previous ModuleManifest PrivateData + $FunctionParameters.Remove('PrivateData') | Out-Null + # Update values with values passed in from function + $PsBoundParameters.GetEnumerator() | ForEach-Object { + If ($FunctionParameters.Contains($_.Key)) + { + $FunctionParameters[$_.Key] = $_.Value + } + Else + { + $FunctionParameters.Add($_.Key, $_.Value) | Out-Null + } + } + } + Else + { + Write-Warning ('Creating new module manifest. Please populate empty fields: ' + $Path) + New-ModuleManifest -Path:($Path) + } + Write-Debug ('Splatting Parameters'); + If ($DebugPreference -ne 'SilentlyContinue') { $FunctionParameters } + New-ModuleManifest @FunctionParameters + } + End + { + # Validate that the module manifest is valid + $ModuleValid = Test-ModuleManifest -Path:($FilePath_psd1.FullName) + If ($ModuleValid) + { + $ModuleValid + } + Else + { + $ModuleValid + Write-Error ('ModuleManifest is invalid!') + } + } +} \ No newline at end of file diff --git a/PowerShell/Deploy/Functions/Get-PSGalleryModuleVersion.ps1 b/PowerShell/Deploy/Functions/Get-PSGalleryModuleVersion.ps1 new file mode 100755 index 000000000..079ee10c8 --- /dev/null +++ b/PowerShell/Deploy/Functions/Get-PSGalleryModuleVersion.ps1 @@ -0,0 +1,54 @@ +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 + ) + # Check to see if module already exists to set version number + $PowerShellGalleryModule = Find-Module -Name:($Name) -ErrorAction:('Ignore') + If ([string]::IsNullOrEmpty($PowerShellGalleryModule)) + { + $ModuleVersion = [PSCustomObject]@{ + 'Name' = $Name; + 'Version' = 'N/A'; + 'Major' = 'N/A'; + 'Minor' = 'N/A'; + 'Patch' = 'N/A'; + } + $NextVersion = Switch ($RELEASETYPE) + { + 'Major' { $ModuleVersion.Major = '1.0.0' } + 'Minor' { $ModuleVersion.Minor = '0.1.0' } + 'Patch' { $ModuleVersion.Patch = '0.0.1' } + } + } + Else + { + $ModuleVersion = [PSCustomObject]@{ + 'Name' = $PowerShellGalleryModule.Name; + 'Version' = $PowerShellGalleryModule.Version; + 'Major' = [int]($PowerShellGalleryModule.Version -split '\.')[0]; + 'Minor' = [int]($PowerShellGalleryModule.Version -split '\.')[1]; + 'Patch' = [int]($PowerShellGalleryModule.Version -split '\.')[2]; + } + Switch ($RELEASETYPE) + { + 'Major' + { + $ModuleVersion.Major = $ModuleVersion.Major + 1 + $ModuleVersion.Minor = 0 + $ModuleVersion.Patch = 0 + } + 'Minor' + { + $ModuleVersion.Minor = $ModuleVersion.Minor + 1 + $ModuleVersion.Patch = 0 + } + 'Patch' { $ModuleVersion.Patch = $ModuleVersion.Patch + 1 } + } + + } + $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/Functions/Invoke-Git.ps1 b/PowerShell/Deploy/Functions/Invoke-Git.ps1 new file mode 100755 index 000000000..911b0e423 --- /dev/null +++ b/PowerShell/Deploy/Functions/Invoke-Git.ps1 @@ -0,0 +1,18 @@ +Function Invoke-Git +{ + Param($Arguments) + If ([environment]::OSVersion.Platform -eq 'Win32NT') { $env:GIT_REDIRECT_STDERR = '2>&1' } + $LASTEXITCODE = 0 + $Error.Clear() + $Command = 'git ' + $Arguments + Write-Host ('[GitCommand]' + $Command) + Invoke-Expression -Command:($Command) + If ($LASTEXITCODE) + { + Throw ('Git error, $LASTEXITCODE: ' + $LASTEXITCODE) + } + If ($Error) + { + Throw ('Git error, $Error: ' + $Error) + } +} \ No newline at end of file diff --git a/PowerShell/Deploy/Functions/Invoke-GitClone.ps1 b/PowerShell/Deploy/Functions/Invoke-GitClone.ps1 new file mode 100755 index 000000000..1621b6b2d --- /dev/null +++ b/PowerShell/Deploy/Functions/Invoke-GitClone.ps1 @@ -0,0 +1,15 @@ +Function Invoke-GitClone +{ + param ( + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)][ValidateNotNullOrEmpty()][string]$Repo + ) + # Logging + $MyName = $MyInvocation.MyCommand.Name + $ParentScriptName = (Get-PSCallStack | Where-Object { $_.Command -notin ($MyName, $MyName.Replace('.ps1', '')) }).Command -join ',' + $UserEmail = 'AzurePipelines@FakeEmail.com' + $UserName = 'AzurePipelines' + Invoke-Git -Arguments:('config user.email "' + $UserEmail + '";') + Invoke-Git -Arguments:('config user.name "' + $UserName + '";') + Invoke-Git -Arguments:('clone ' + $Repo + ';') + Invoke-Git -Arguments:('status;') +} \ No newline at end of file diff --git a/PowerShell/Deploy/Functions/Invoke-GitCommit.ps1 b/PowerShell/Deploy/Functions/Invoke-GitCommit.ps1 new file mode 100755 index 000000000..3e8175998 --- /dev/null +++ b/PowerShell/Deploy/Functions/Invoke-GitCommit.ps1 @@ -0,0 +1,18 @@ +Function Invoke-GitCommit +{ + param ( + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)][ValidateNotNullOrEmpty()][string]$BranchName + ) + # Logging + $MyName = $MyInvocation.MyCommand.Name + $ParentScriptName = (Get-PSCallStack | Where-Object { $_.Command -notin ($MyName, $MyName.Replace('.ps1', '')) }).Command -join ',' + $CommitMessage = 'Push to ' + $BranchName + '; Called by:' + $ParentScriptName + ';[skip ci]' + $UserEmail = 'AzurePipelines@FakeEmail.com' + $UserName = 'AzurePipelines' + Invoke-Git -Arguments:('config user.email "' + $UserEmail + '";') + Invoke-Git -Arguments:('config user.name "' + $UserName + '";') + Invoke-Git -Arguments:('add -A;') + Invoke-Git -Arguments:('status;') + Invoke-Git -Arguments:('commit -m ' + '"' + $CommitMessage + '";') + Invoke-Git -Arguments:('push origin HEAD:refs/heads/' + $BranchName + ';') +} diff --git a/PowerShell/Deploy/Functions/New-DynamicParameter.ps1 b/PowerShell/Deploy/Functions/New-DynamicParameter.ps1 new file mode 100755 index 000000000..d28a0941a --- /dev/null +++ b/PowerShell/Deploy/Functions/New-DynamicParameter.ps1 @@ -0,0 +1,288 @@ +Function New-DynamicParameter () +{ + <# + .SYNOPSIS + Expedites creating PowerShell cmdlet dynamic parameters. + .DESCRIPTION + This cmdlet facilitates the easy creation of dynamic parameters. + .PARAMETER Name + The name of the parameter. + .PARAMETER Type + The type of the parameter, this defaults to System.String. + .PARAMETER Mandatory + Indicates whether the parameter is required when the cmdlet or function is run. + .PARAMETER ParameterSets + The name of the parameter sets to which this parameter belongs. This defaults to __AllParameterSets. + .PARAMETER Position + The position of the parameter in the command-line string. + .PARAMETER ValueFromPipeline + Indicates whether the parameter can take values from incoming pipeline objects. + .PARAMETER ValueFromPipelineByPropertyName + Indicates that the parameter can take values from a property of the incoming pipeline object that has the same name as this parameter. For example, if the name of the cmdlet or function parameter is userName, the parameter can take values from the userName property of incoming objects. + .PARAMETER ValueFromRemainingArguments + Indicates whether the cmdlet parameter accepts all the remaining command-line arguments that are associated with this parameter. + .PARAMETER HelpMessage + A short description of the parameter. + .PARAMETER DontShow + Indicates that this parameter should not be shown to the user in this like intellisense. This is primarily to be used in functions that are implementing the logic for dynamic keywords. + .PARAMETER Alias + Declares a alternative namea for the parameter. + .PARAMETER ValidateNotNull + Validates that the argument of an optional parameter is not null. + .PARAMETER ValidateNotNullOrEmpty + Validates that the argument of an optional parameter is not null, an empty string, or an empty collection. + .PARAMETER AllowEmptyString + Allows Empty strings. + .PARAMETER AllowNull + Allows null values. + .PARAMETER AllowEmptyCollection + Allows empty collections. + .PARAMETER ValidateScript + Defines an attribute that uses a script to validate a parameter of any Windows PowerShell function. + .PARAMETER ValidateSet + Defines an attribute that uses a set of values to validate a cmdlet parameter argument. + .PARAMETER ValidateRange + Defines an attribute that uses minimum and maximum values to validate a cmdlet parameter argument. + .PARAMETER ValidateCount + Defines an attribute that uses maximum and minimum limits to validate the number of arguments that a cmdlet parameter accepts. + .PARAMETER ValidateLength + Defines an attribute that uses minimum and maximum limits to validate the number of characters in a cmdlet parameter argument. + .PARAMETER ValidatePattern + Defines an attribute that uses a regular expression to validate the character pattern of a cmdlet parameter argument. + .PARAMETER RuntimeParameterDictionary + The dictionary to add the new parameter to. If one is not provided, a new dictionary is created and returned to the pipeline. + .EXAMPLE + DynamicParam { + ... + $RuntimeParameterDictionary = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary + New-DynamicParameter -Name "Numbers" -ValidateSet @(1, 2, 3) -Type [System.Int32] -Mandatory -RuntimeParameterDictionary $RuntimeParameterDictionary | Out-Null + ... + return $RuntimeParameterDictionary + } + A new parameter named "Numbers" is added to the cmdlet. The parameter is mandatory and must be 1, 2, or 3. The dictionary sent in is modified and does not need to be received. + .EXAMPLE + DynamicParam { + ... + $Params = @( + @{ + "Name" = "Numbers"; + "ValidateSet" = @(1, 2, 3); + "Type" = [System.Int32] + }, + @{ + "Name" = "FirstName"; + "Type" = [System.String]; + "Mandatory" = $true; + "ParameterSets" = @("Names") + } + ) + $Params | ForEach-Object { + New-Object PSObject -Property $_ + } | New-DynamicParameter + } + The example creates an array of two hashtables. These hashtables are converted into PSObjects so they can match the parameters by property name, then new dynamic parameters are created. All of the + parameters are fed to New-DynamicParameter which returns a single new RuntimeParameterDictionary to the pipeline, which is returned from the DynamicParam section. + .EXAMPLE + Function Invoke-NewDynamicParameterTest + { + [CmdletBinding()] + Param() + DynamicParam + { + # Define new parameters + $Params = @( + @{'Name' = 'Numbers'; 'ValidateSet' = @(1, 2, 3); 'Type' = [System.Int32]}, + @{'Name' = 'FirstName'; 'Type' = [System.String]; 'Mandatory' = $true; 'ParameterSets' = @('Names')} + ) + # Create new parameters + Return $Params | ForEach-Object { + New-Object PSObject -Property:($_) + } | New-DynamicParameter + } + Begin + { + # Create new variables for script + $PsBoundParameters.GetEnumerator() | ForEach-Object {Set-Variable -Name:($_.Key) -Value:($_.Value) -Force} + # Debug message for parameter call + Write-Debug ('[CallFunction]' + $MyInvocation.MyCommand.Name + ' ' + ($PsBoundParameters.GetEnumerator() | Sort-Object Key | ForEach-Object { ('-' + $_.Key + ":('" + ($_.Value -join "','") + "')").Replace("'True'", '$True').Replace("'False'", '$False')}) ) + If($PSCmdlet.ParameterSetName -ne '__AllParameterSets'){Write-Verbose ('[ParameterSet]' + $MyInvocation.MyCommand.Name + ':' + $PSCmdlet.ParameterSetName)} + } + Process + { + Write-Output ('') + Write-Output ('Numbers: ' + [string]$Numbers + '; FirstName: ' + $FirstName + ';') + } + End + { + } + } + Invoke-NewDynamicParameterTest -Numbers:(1) -FirstName:('hello') + .INPUTS + System.Management.Automation.PSObject + .OUTPUTS + System.Management.Automation.RuntimeDefinedParameterDictionary + .NOTES + AUTHOR: Michael Haken + LAST UPDATE: 2/6/2018 + WEBSITE: https://www.powershellgallery.com/packages/BAMCIS.DynamicParam/1.0.0.0/Content/BAMCIS.DynamicParam.psm1 + #> + [CmdletBinding()] + [OutputType([System.Management.Automation.RuntimeDefinedParameterDictionary])] + Param + ( + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)][ValidateNotNullOrEmpty()][System.String]$Name, + # These parameters are part of the standard ParameterAttribute + [Parameter(ValueFromPipelineByPropertyName = $true)][ValidateNotNull()][System.Type]$Type = [System.String], + [Parameter(ValueFromPipelineByPropertyName = $true)][Switch]$Mandatory, + [Parameter(ValueFromPipelineByPropertyName = $true)][ValidateCount(1, [System.Int32]::MaxValue)][System.String[]]$ParameterSets = @("__AllParameterSets"), + [Parameter(ValueFromPipelineByPropertyName = $true)][System.Int32]$Position = [System.Int32]::MinValue, + [Parameter(ValueFromPipelineByPropertyName = $true)][Switch]$ValueFromPipeline, + [Parameter(ValueFromPipelineByPropertyName = $true)][Switch]$ValueFromPipelineByPropertyName, + [Parameter(ValueFromPipelineByPropertyName = $true)][Switch]$ValueFromRemainingArguments, + [Parameter(ValueFromPipelineByPropertyName = $true)][ValidateNotNullOrEmpty()][System.String]$HelpMessage, + [Parameter(ValueFromPipelineByPropertyName = $true)][Switch]$DontShow, + # These parameters are each their own attribute + [Parameter(ValueFromPipelineByPropertyName = $true)][System.String[]]$Alias = @(), + [Parameter(ValueFromPipelineByPropertyName = $true)][Switch]$ValidateNotNull, + [Parameter(ValueFromPipelineByPropertyName = $true)][Switch]$ValidateNotNullOrEmpty, + [Parameter(ValueFromPipelineByPropertyName = $true)][Switch]$AllowEmptyString, + [Parameter(ValueFromPipelineByPropertyName = $true)][Switch]$AllowNull, + [Parameter(ValueFromPipelineByPropertyName = $true)][Switch]$AllowEmptyCollection, + [Parameter(ValueFromPipelineByPropertyName = $true)][ValidateNotNullOrEmpty()][System.Management.Automation.ScriptBlock]$ValidateScript, + [Parameter(ValueFromPipelineByPropertyName = $true)][ValidateNotNull()][System.String[]]$ValidateSet = @(), + [Parameter(ValueFromPipelineByPropertyName = $true)][ValidateNotNullOrEmpty()][ValidateCount(2, 2)][System.Int32[]]$ValidateRange = $null, + [Parameter(ValueFromPipelineByPropertyName = $true)][ValidateNotNullOrEmpty()][ValidateCount(2, 2)][System.Int32[]]$ValidateCount = $null, + [Parameter(ValueFromPipelineByPropertyName = $true)][ValidateNotNullOrEmpty()][ValidateCount(2, 2)][System.Int32[]]$ValidateLength = $null, + [Parameter(ValueFromPipelineByPropertyName = $true)][ValidateNotNullOrEmpty()][System.String]$ValidatePattern = $null, + [Parameter(ValueFromPipelineByPropertyName = $true)][ValidateNotNull()][System.Management.Automation.RuntimeDefinedParameterDictionary]$RuntimeParameterDictionary = $null + ) + Begin + { + If ($RuntimeParameterDictionary -eq $null) + { + $RuntimeParameterDictionary = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary + } + } + Process + { + # Create the collection of attributes + $AttributeCollection = New-Object -TypeName System.Collections.ObjectModel.Collection[System.Attribute] + ForEach ($Set In $ParameterSets) + { + # Create and set the parameter's attributes + $ParameterAttribute = New-Object -TypeName System.Management.Automation.PARAMETERAttribute + If (-not [System.String]::IsNullOrEmpty($Set)) + { + $ParameterAttribute.ParameterSetName = $Set + } + If ($Position -ne $null) + { + $ParameterAttribute.Position = $Position + } + If ($Mandatory) + { + $ParameterAttribute.Mandatory = $true + } + If ($ValueFromPipeline) + { + $ParameterAttribute.ValueFromPipeline = $true + } + If ($ValueFromPipelineByPropertyName) + { + $ParameterAttribute.ValueFromPipelineByPropertyName = $true + } + If ($ValueFromRemainingArguments) + { + $ParameterAttribute.ValueFromRemainingArguments = $true + } + If (-not [System.String]::IsNullOrEmpty($HelpMessage)) + { + $ParameterAttribute.HelpMessage = $HelpMessage + } + If ($DontShow) + { + $ParameterAttribute.DontShow = $true + } + $AttributeCollection.Add($ParameterAttribute) + } + If ($Alias.Length -gt 0) + { + $AliasAttribute = New-Object -TypeName System.Management.Automation.AliasAttribute($Alias) + $AttributeCollection.Add($AliasAttribute) + } + If ($ValidateSet.Length -gt 0) + { + $ValidateSetAttribute = New-Object -TypeName System.Management.Automation.ValidateSetAttribute($ValidateSet) + $AttributeCollection.Add($ValidateSetAttribute) + } + If ($ValidateScript -ne $null) + { + $ValidateScriptAttribute = New-Object -TypeName System.Management.Automation.ValidateScriptAttribute($ValidateScript) + $AttributeCollection.Add($ValidateScriptAttribute) + } + If ($ValidateCount -ne $null -and $ValidateCount.Length -eq 2) + { + $ValidateCountAttribute = New-Object -TypeName System.Management.Automation.ValidateCountAttribute($ValidateCount[0], $ValidateCount[1]) + $AttributeCollection.Add($ValidateCountAttribute) + } + If ($ValidateLength -ne $null -and $ValidateLength -eq 2) + { + $ValidateLengthAttribute = New-Object -TypeName System.Management.Automation.ValidateLengthAttribute($ValidateLength[0], $ValidateLength[1]) + $AttributeCollection.Add($ValidateLengthAttribute) + } + If (-not [System.String]::IsNullOrEmpty($ValidatePattern)) + { + $ValidatePatternAttribute = New-Object -TypeName System.Management.Automation.ValidatePatternAttribute($ValidatePattern) + $AttributeCollection.Add($ValidatePatternAttribute) + } + If ($ValidateRange -ne $null -and $ValidateRange.Length -eq 2) + { + $ValidateRangeAttribute = New-Object -TypeName System.Management.Automation.ValidateRangeAttribute($ValidateRange) + $AttributeCollection.Add($ValidateRangeAttribute) + } + If ($ValidateNotNull) + { + $NotNullAttribute = New-Object -TypeName System.Management.Automation.ValidateNotNullAttribute + $AttributeCollection.Add($NotNullAttribute) + } + If ($ValidateNotNullOrEmpty) + { + $NotNullOrEmptyAttribute = New-Object -TypeName System.Management.Automation.ValidateNotNullOrEmptyAttribute + $AttributeCollection.Add($NotNullOrEmptyAttribute) + } + If ($AllowEmptyString) + { + $AllowEmptyStringAttribute = New-Object -TypeName System.Management.Automation.AllowEmptyStringAttribute + $AttributeCollection.Add($AllowEmptyStringAttribute) + } + If ($AllowEmptyCollection) + { + $AllowEmptyCollectionAttribute = New-Object -TypeName System.Management.Automation.AllowEmptyCollectionAttribute + $AttributeCollection.Add($AllowEmptyCollectionAttribute) + } + If ($AllowNull) + { + $AllowNullAttribute = New-Object -TypeName System.Management.Automation.AllowNullAttribute + $AttributeCollection.Add($AllowNullAttribute) + } + If (-not $RuntimeParameterDictionary.ContainsKey($Name)) + { + $RuntimeParameter = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter($Name, $Type, $AttributeCollection) + $RuntimeParameterDictionary.Add($Name, $RuntimeParameter) + } + Else + { + ForEach ($Attr In $AttributeCollection.GetEnumerator()) + { + If (-not $RuntimeParameterDictionary.$Name.Attributes.Contains($Attr)) + { + $RuntimeParameterDictionary.$Name.Attributes.Add($Attr) + } + } + } + } + End + { + Write-Output -InputObject $RuntimeParameterDictionary + } +} diff --git a/PowerShell/Deploy/Functions/New-FolderRecursive.ps1 b/PowerShell/Deploy/Functions/New-FolderRecursive.ps1 new file mode 100755 index 000000000..462cd8e07 --- /dev/null +++ b/PowerShell/Deploy/Functions/New-FolderRecursive.ps1 @@ -0,0 +1,53 @@ + +#Function to create a folder and any child folders +Function New-FolderRecursive +{ + [cmdletbinding(SupportsShouldProcess = $True)] + Param( + [string]$Path + , [switch]$Force + ) + $StartLocation = Get-Location + $CurrentLocation = $StartLocation + $PathPart = @() + # Determin OS specific variables + $WindowsDeliminator = '\' + $UnixDeliminator = '/' + $PathDeliminator = Switch ([environment]::OSVersion.Platform) { 'Win32NT' { $WindowsDeliminator }'Unix' { $UnixDeliminator } } + $RegEx_ExcludePathDeliminator = ('[^\' + $WindowsDeliminator + '|\' + $UnixDeliminator + ']') + $RegEx_IncludePathDeliminator = ('[\' + $WindowsDeliminator + '|\' + $UnixDeliminator + ']') + # Normalize path deliminator based upon OS + $NormalizedPath = $Path -replace ($RegEx_IncludePathDeliminator, $PathDeliminator) + # Determine if the last part of the path contains a file extension + If ( (Split-Path -Path:($NormalizedPath) -Leaf) -match '\.[a-zA-Z0-9]+$') + { + $NormalizedPath = Split-Path -Path:($NormalizedPath) -Parent + } + # Remove Deliminator from strings to do a comparison + $NormalizedPath_NoDeliminator = $NormalizedPath -replace ($RegEx_IncludePathDeliminator, '') + $CurrentLocation_NoDeliminator = $CurrentLocation -replace ($RegEx_IncludePathDeliminator, '') + # If the current path is not in the path passed in then reset the current location + If ( $NormalizedPath_NoDeliminator -notmatch $CurrentLocation_NoDeliminator) { Set-Location; $CurrentLocation = Get-Location; } + # Remove the current location from the path so it does not get recreated + $NormalizedPath = $NormalizedPath.Replace($CurrentLocation, ''); + # Split path into each folder + $SplitFullPath = $NormalizedPath -split $RegEx_IncludePathDeliminator + ForEach ( $Directory In $SplitFullPath | Where-Object { $_ -and $_ -notin ($WindowsDeliminator, $UnixDeliminator) } ) + { + $PathPart += $Directory + $NewPath = $PathPart -join $PathDeliminator + If ( !( Test-Path -Path:($NewPath) )) + { + If ($Force) + { + New-Item -ItemType:('directory') -Path:($NewPath) -Force + } + Else + { + New-Item -ItemType:('directory') -Path:($NewPath) + } + } + } + # Reset the location back to where the script started + Set-Location -Path:($StartLocation) | Out-Null +} \ No newline at end of file diff --git a/PowerShell/Deploy/Functions/New-ModuleBanner.ps1 b/PowerShell/Deploy/Functions/New-ModuleBanner.ps1 new file mode 100755 index 000000000..c98efcf3f --- /dev/null +++ b/PowerShell/Deploy/Functions/New-ModuleBanner.ps1 @@ -0,0 +1,26 @@ +Function New-ModuleBanner +{ + Param( + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)][ValidateNotNullOrEmpty()][System.String]$LatestVersion + , [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)][ValidateNotNullOrEmpty()][System.String]$BannerCurrent + , [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 2)][ValidateNotNullOrEmpty()][System.String]$BannerOld + ) + $Content = "#### Latest Version + +`````` +{0} +`````` + +#### Banner Current + +`````` +{1} +`````` + +#### Banner Old + +`````` +{2} +``````" + Return ($Content -f $LatestVersion, $BannerCurrent, $BannerOld) +} \ No newline at end of file diff --git a/PowerShell/Deploy/Functions/New-ModuleChangeLog.ps1 b/PowerShell/Deploy/Functions/New-ModuleChangeLog.ps1 new file mode 100755 index 000000000..659502133 --- /dev/null +++ b/PowerShell/Deploy/Functions/New-ModuleChangeLog.ps1 @@ -0,0 +1,35 @@ + +Function New-ModuleChangelog +{ + Param( + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)][ValidateNotNullOrEmpty()][System.String]$LatestVersion + , [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)][ValidateNotNullOrEmpty()][System.String]$ReleaseNotes + , [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 2)][ValidateNotNullOrEmpty()][System.String]$Features + , [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 3)][ValidateNotNullOrEmpty()][System.String]$Improvements + , [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 4)][ValidateNotNullOrEmpty()][System.String]$BugFixes + ) + $Content = "## {0} + +Release Date: $(Get-Date -UFormat:('%B %d, %Y')) + +#### RELEASE NOTES + +``````` +{1} +``````` + +#### FEATURES: + +{2} + +#### IMPROVEMENTS: + +{3} + +#### BUG FIXES: + +{4} + +" + Return ($Content -f $LatestVersion, $ReleaseNotes, $Features, $Improvements, $BugFixes) +} \ No newline at end of file diff --git a/PowerShell/Deploy/Functions/Write-Log.ps1 b/PowerShell/Deploy/Functions/Write-Log.ps1 new file mode 100755 index 000000000..71b251666 --- /dev/null +++ b/PowerShell/Deploy/Functions/Write-Log.ps1 @@ -0,0 +1,53 @@ +#Function to log information/error in console and file +Function Write-Log +{ + Param( + [Parameter(Mandatory = $true, Position = 0)][ValidateNotNullOrEmpty()]$Message, + [Parameter(Mandatory = $false, Position = 1)][ValidateNotNullOrEmpty()] [string]$color = 'Gray', + [Parameter(Mandatory = $false, Position = 2)][ValidateNotNullOrEmpty()] [bool]$showInConsole = $true, + [Parameter(Mandatory = $false, Position = 3)][ValidateNotNullOrEmpty()] [bool]$exitInd = $false + ) + $Error = '' + If ($color.ToLower() -eq 'Red') + { + $Error = "[ERROR]" + } + If ($color.ToLower() -eq 'Yellow') + { + $Error = "[WARNING]" + } + If ($showInConsole -eq $true) + { + $CurrentVerbosePreference = $VerbosePreference + $VerbosePreference = "Continue" + $HostInfo = Get-Host + If ($HostInfo.Name -notin ('Default Host', 'ServerRemoteHost')) + { + $VerboseForegroundColorOrg = $HostInfo.PrivateData.VerboseForegroundColor + $HostInfo.PrivateData.VerboseForegroundColor = $color + } + Write-Verbose ("`r`n" + $Error + $Message) + If ($HostInfo.Name -notin ('Default Host', 'ServerRemoteHost')) + { + $HostInfo.PrivateData.VerboseForegroundColor = $VerboseForegroundColorOrg + } + $VerbosePreference = $CurrentVerbosePreference + } + If ($exitInd) + { + $Error = "[EXITING SCRIPT]" + If ($LogFullPath) + { + ($Error + $Message) | Out-File -FilePath:($LogFullPath) -Append -ErrorAction:($ErrorActionPreference) -WhatIf:($WhatIfPreference) + } + Write-Error ($Error + $Message) + Break + } + Else + { + If ($LogFullPath) + { + ($Error + $Message) | Out-File -FilePath:($LogFullPath) -Append -ErrorAction:($ErrorActionPreference) -WhatIf:($WhatIfPreference) + } + } +} \ No newline at end of file diff --git a/PowerShell/Deploy/Get-Config.ps1 b/PowerShell/Deploy/Get-Config.ps1 new file mode 100755 index 000000000..c19887674 --- /dev/null +++ b/PowerShell/Deploy/Get-Config.ps1 @@ -0,0 +1,60 @@ +# Log statuses +Write-Host ('[status]Platform: ' + [environment]::OSVersion.Platform) +Write-Host ('[status]PowerShell Version: ' + ($PSVersionTable.PSVersion -join '.')) +Write-Host ('[status]Host: ' + (Get-Host).Name) +Write-Host ('[status]Loaded config: ' + $MyInvocation.MyCommand.Path) +# Set variables from Azure Pipelines +$ModuleName = $env:MODULENAME +$ModuleFolderName = $env:MODULEFOLDERNAME +$GitSourceBranch = $env:BUILD_SOURCEBRANCHNAME +$GitSourceRepo = $env:BUILD_REPOSITORY_URI +$StagingDirectory = $env:BUILD_ARTIFACTSTAGINGDIRECTORY +$GitSourceRepoWiki = $GitSourceRepo + '.wiki' +$ScriptRoot = Switch ($env:DEPLOYFOLDER) { $true { $env:DEPLOYFOLDER } Default { $PSScriptRoot } } +$FolderPath_ModuleRootPath = (Get-Item -Path:($ScriptRoot)).Parent.FullName +$RELEASETYPE = $env:RELEASETYPE +$XAPIKEY_PESTER = $env:XAPIKEY_PESTER +$XAPIKEY_MTP = $env:XAPIKEY_MTP +$NUGETAPIKEY = $env:NUGETAPIKEY +$EnvironmentConfig = 'TestEnvironmentVariables.ps1' +$GitHubWikiUrl = 'https://github.com/TheJumpCloud/support/wiki/' +$FilePath_ModuleBanner = $FolderPath_ModuleRootPath + '/ModuleBanner.md' +$FilePath_ModuleChangelog = $FolderPath_ModuleRootPath + '/ModuleChangelog.md' +# Define required files and folders variables +$RequiredFiles = ('LICENSE', 'psm1', 'psd1', 'PesterConfig') +$RequiredFolders = ('Docs', 'Private', 'Public', 'Tests', 'en-US') +# Define folder path variables +$FolderPath_Module = $FolderPath_ModuleRootPath + '/' + $ModuleFolderName +$RequiredFolders | ForEach-Object { + $FolderName = $_ + $FolderPath = $FolderPath_Module + '/' + $FolderName + New-Variable -Name:('FolderName_' + $_.Replace('-', '')) -Value:($FolderName) -Force; + New-Variable -Name:('FolderPath_' + $_.Replace('-', '')) -Value:($FolderPath) -Force +} +$RequiredFiles | ForEach-Object { + $FileName = If ($_ -in ('psm1', 'psd1')) { $ModuleName + '.' + $_ } ElseIf ($_ -eq 'PesterConfig') { $EnvironmentConfig } Else { $_ } + $FilePath = If ($_ -eq 'PesterConfig') { $FolderPath_Module + '/' + $FolderName_Tests + '/' + $FileName } Else { $FolderPath_Module + '/' + $FileName } + New-Variable -Name:('FileName_' + $_) -Value:($FileName) -Force; + New-Variable -Name:('FilePath_' + $_) -Value:($FilePath) -Force; +} +# 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 } +# Load deploy functions +$DeployFunctions = @(Get-ChildItem -Path:($PSScriptRoot + '/Functions/*.ps1') -Recurse) +Foreach ($DeployFunction In $DeployFunctions) +{ + Try + { + . $DeployFunction.FullName + } + Catch + { + Write-Error -Message:('Failed to import function: ' + $DeployFunction.FullName) + } +} +# Install NuGet +If (!(Get-PackageProvider -Name:('NuGet') -ListAvailable -ErrorAction:('SilentlyContinue'))) +{ + Write-Host ('[status]Installing package provider NuGet'); Install-PackageProvider -Name:('NuGet') -Scope:('CurrentUser') -Force +} diff --git a/PowerShell/Deploy/Get-SessionVariables.ps1 b/PowerShell/Deploy/Get-SessionVariables.ps1 new file mode 100755 index 000000000..a5058e8e2 --- /dev/null +++ b/PowerShell/Deploy/Get-SessionVariables.ps1 @@ -0,0 +1,8 @@ +Write-Host ('Imported Environment Variables') -BackgroundColor:('Green') -ForegroundColor:('Black') +Get-ChildItem Env: | Format-Table + +Write-Host ('PsBoundParameters') -BackgroundColor:('Green') -ForegroundColor:('Black') +$PsBoundParameters.GetEnumerator() + +Write-Host ('Imported Variables') -BackgroundColor:('Green') -ForegroundColor:('Black') +Get-Variable | Format-Table \ No newline at end of file diff --git a/PowerShell/Deploy/Publish-ToPowerShellGallery.ps1 b/PowerShell/Deploy/Publish-ToPowerShellGallery.ps1 new file mode 100755 index 000000000..834801e86 --- /dev/null +++ b/PowerShell/Deploy/Publish-ToPowerShellGallery.ps1 @@ -0,0 +1,4 @@ +. ($PSScriptRoot + '/' + 'Get-Config.ps1') +########################################################################### +Write-Host ('[status]Publishing to PowerShell Gallery:' + $FolderPath_Module) +Publish-Module -Path:($FolderPath_Module) -NuGetApiKey:($NUGETAPIKEY) \ No newline at end of file diff --git a/PowerShell/Deploy/Tests/PSScriptAnalyzer.Tests.ps1 b/PowerShell/Deploy/Tests/PSScriptAnalyzer.Tests.ps1 new file mode 100755 index 000000000..8a627eeed --- /dev/null +++ b/PowerShell/Deploy/Tests/PSScriptAnalyzer.Tests.ps1 @@ -0,0 +1,33 @@ +. ((Get-Item -Path:($PSScriptRoot)).Parent.FullName + '/' + 'Get-Config.ps1') +########################################################################### +# # Describe "PSScriptAnalyzer Tests" { +# # BeforeAll { +# # # $DebugPreference = 'Continue' +# # # $VerbosePreference = 'Continue' +# # $ErrorActionPreference = 'Stop' +# # } +# # AfterAll { +# # # $DebugPreference = 'SilentlyContinue' +# # # $VerbosePreference = 'SilentlyContinue' +# # $ErrorActionPreference = 'Continue' +# # } +# # Context 'PSScriptAnalyzer Tests' { +# # It 'Passes Invoke-PSScriptAnalyzer' { +Write-Host ('[status]Installing module: PSScriptAnalyzer') +Install-Module -Name:('PSScriptAnalyzer') -Force -Scope:('CurrentUser') +Write-Host ('[status]Running PSScriptAnalyzer on: ' + $FolderPath_Module) +$ScriptAnalyzerResults = Invoke-ScriptAnalyzer -Path:($FolderPath_Module) -Recurse +# # $ScriptAnalyzerResults | Should BeNullOrEmpty +# # $? | Should Be $true +# # } +If ($ScriptAnalyzerResults) +{ + $ScriptAnalyzerResults + Write-Error ('Go fix the ScriptAnalyzer results!') +} +Else +{ + Write-Host ('[success]ScriptAnalyzer returned no results') +} +# # } +# # } \ No newline at end of file diff --git a/PowerShell/Deploy/Tests/PSScriptInfo.Tests.ps1 b/PowerShell/Deploy/Tests/PSScriptInfo.Tests.ps1 new file mode 100755 index 000000000..41d987426 --- /dev/null +++ b/PowerShell/Deploy/Tests/PSScriptInfo.Tests.ps1 @@ -0,0 +1,68 @@ +. ((Get-Item -Path:($PSScriptRoot)).Parent.FullName + '/' + 'Get-Config.ps1') +########################################################################### +# # Describe "ScriptInfo Tests" { +# # BeforeAll { +# # # $DebugPreference = 'Continue' +# # # $VerbosePreference = 'Continue' +# # $ErrorActionPreference = 'Stop' +# # } +# # AfterAll { +# # # $DebugPreference = 'SilentlyContinue' +# # # $VerbosePreference = 'SilentlyContinue' +# # $ErrorActionPreference = 'Continue' +# # } +# # Context 'ScriptInfo Tests' { +# # It 'Passes Test-ScriptFileInfo' { +$ScriptFileInfoResults = Get-ChildItem -Path:($FolderPath_Public) -Recurse -File | ForEach-Object { Test-ScriptFileInfo -Path:($_.FullName) -ErrorAction:('Ignore') } +# # $ScriptFileInfoResults | Should BeNullOrEmpty +# # $? | Should Be $true +# # } +If ($ScriptFileInfoResults) +{ + $ScriptFileInfoResults + Write-Error ('Go fix the ScriptFileInfo results!') +} +Else +{ + Write-Host ('[success]ScriptFileInfo returned no results') +} +# # } +# # } + +# Test-ScriptFileInfo -Path:('') + +# New-ScriptFileInfo -Path:('') ` +# -Description:('') ` +# -Version:('') ` +# -Guid:('') ` +# -Author:('') ` +# -CompanyName:('') ` +# -Copyright:('') ` +# -RequiredModules:('') ` +# -ExternalModuleDependencies:('') ` +# -RequiredScripts:('') ` +# -ExternalScriptDependencies:('') ` +# -Tags:('') ` +# -ProjectUri:('') ` +# -LicenseUri:('') ` +# -IconUri:('') ` +# -ReleaseNotes:('') ` +# -PrivateData:('') + +# Update-ScriptFileInfo -Path:('') ` +# -Description:('') ` +# -Version:('') ` +# -Guid:('') ` +# -Author:('') ` +# -CompanyName:('') ` +# -Copyright:('') ` +# -RequiredModules:('') ` +# -ExternalModuleDependencies:('') ` +# -RequiredScripts:('') ` +# -ExternalScriptDependencies:('') ` +# -Tags:('') ` +# -ProjectUri:('') ` +# -LicenseUri:('') ` +# -IconUri:('') ` +# -ReleaseNotes:('') ` +# -PrivateData:('') diff --git a/PowerShell/JumpCloud Module/.DS_Store b/PowerShell/JumpCloud Module/.DS_Store deleted file mode 100644 index 178b26516..000000000 Binary files a/PowerShell/JumpCloud Module/.DS_Store and /dev/null differ diff --git a/PowerShell/JumpCloud Module/Docs/.DS_Store b/PowerShell/JumpCloud Module/Docs/.DS_Store deleted file mode 100755 index 5008ddfcf..000000000 Binary files a/PowerShell/JumpCloud Module/Docs/.DS_Store and /dev/null differ diff --git a/PowerShell/JumpCloud Module/Docs/Add-JCAssociation.md b/PowerShell/JumpCloud Module/Docs/Add-JCAssociation.md index 0d305e474..9a8e85be9 100644 --- a/PowerShell/JumpCloud Module/Docs/Add-JCAssociation.md +++ b/PowerShell/JumpCloud Module/Docs/Add-JCAssociation.md @@ -14,14 +14,23 @@ Create an association between two object within the JumpCloud console. ### ById (Default) ``` -Add-JCAssociation [-Type] [-Force] [-Id] [-TargetType] [[-TargetId] ] - [[-TargetName] ] [[-Attributes] ] [] +Add-JCAssociation [-Type] [-Force] [-Fields ] [-Filter ] [-Id] + [-Limit ] [-Paginate ] [-Skip ] [[-Attributes] ] [[-TargetId] ] + [[-TargetName] ] [[-TargetType] ] [] ``` ### ByName ``` -Add-JCAssociation [-Type] [-Force] [-Name] [-TargetType] [[-TargetId] ] - [[-TargetName] ] [[-Attributes] ] [] +Add-JCAssociation [-Type] [-Force] [-Fields ] [-Filter ] [-Limit ] + [-Name] [-Paginate ] [-Skip ] [[-Attributes] ] [[-TargetId] ] + [[-TargetName] ] [[-TargetType] ] [] +``` + +### ByValue +``` +Add-JCAssociation [-Type] [-Force] [-Fields ] [-Filter ] [-Limit ] + [-Paginate ] [-Skip ] [[-Attributes] ] [[-TargetId] ] + [[-TargetName] ] [[-TargetType] ] [] ``` ## DESCRIPTION @@ -96,7 +105,7 @@ The name of the object. ```yaml Type: String[] Parameter Sets: ByName -Aliases: domain, displayName, username +Aliases: displayName, username Required: True Position: 4 @@ -144,7 +153,7 @@ Parameter Sets: (All) Aliases: TargetSingular Accepted values: user, user_group, system, system_group, policy, command, application, g_suite, ldap_server, office_365, radius_server -Required: True +Required: False Position: 5 Default value: None Accept pipeline input: True (ByPropertyName) @@ -167,6 +176,81 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -Fields +An array of the fields/properties/columns you want to return from the search. + +```yaml +Type: Array +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Filter +Filters to narrow down search. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Limit +The number of items you want to return per API call. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Skip +Ignores the specified number of objects and then gets the remaining objects. Enter the number of objects to skip. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Paginate +Whether or not you want to paginate through the results. + +```yaml +Type: Boolean +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +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). diff --git a/PowerShell/JumpCloud Module/Docs/Get-JCAssociation.md b/PowerShell/JumpCloud Module/Docs/Get-JCAssociation.md index 5d2135b73..bdeef3103 100644 --- a/PowerShell/JumpCloud Module/Docs/Get-JCAssociation.md +++ b/PowerShell/JumpCloud Module/Docs/Get-JCAssociation.md @@ -14,14 +14,23 @@ The function Get-JCAssociation can be used to query an object's associations and ### ById (Default) ``` -Get-JCAssociation [-Type] [-Force] [-Id] [-TargetType] [-Direct] [-Indirect] - [-IncludeInfo] [-IncludeNames] [-IncludeVisualPath] [] +Get-JCAssociation [-Type] [-Force] [-Fields ] [-Filter ] [-Id] + [-Limit ] [-Paginate ] [-Skip ] [-Direct] [-IncludeInfo] [-IncludeNames] + [-IncludeVisualPath] [-Indirect] [[-TargetType] ] [] ``` ### ByName ``` -Get-JCAssociation [-Type] [-Force] [-Name] [-TargetType] [-Direct] [-Indirect] - [-IncludeInfo] [-IncludeNames] [-IncludeVisualPath] [] +Get-JCAssociation [-Type] [-Force] [-Fields ] [-Filter ] [-Limit ] + [-Name] [-Paginate ] [-Skip ] [-Direct] [-IncludeInfo] [-IncludeNames] + [-IncludeVisualPath] [-Indirect] [[-TargetType] ] [] +``` + +### ByValue +``` +Get-JCAssociation [-Type] [-Force] [-Fields ] [-Filter ] [-Limit ] + [-Paginate ] [-Skip ] [-Direct] [-IncludeInfo] [-IncludeNames] [-IncludeVisualPath] + [-Indirect] [[-TargetType] ] [] ``` ## DESCRIPTION @@ -177,7 +186,7 @@ The name of the object. ```yaml Type: String[] Parameter Sets: ByName -Aliases: domain, displayName, username +Aliases: displayName, username Required: True Position: 4 @@ -195,7 +204,7 @@ Parameter Sets: (All) Aliases: TargetSingular Accepted values: user, user_group, system, system_group, policy, command, application, g_suite, ldap_server, office_365, radius_server -Required: True +Required: False Position: 5 Default value: None Accept pipeline input: True (ByPropertyName) @@ -218,6 +227,81 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -Fields +An array of the fields/properties/columns you want to return from the search. + +```yaml +Type: Array +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Filter +Filters to narrow down search. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Limit +The number of items you want to return per API call. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Skip +Ignores the specified number of objects and then gets the remaining objects. Enter the number of objects to skip. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Paginate +Whether or not you want to paginate through the results. + +```yaml +Type: Boolean +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +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). diff --git a/PowerShell/JumpCloud Module/Docs/Get-JCCommandTarget.md b/PowerShell/JumpCloud Module/Docs/Get-JCCommandTarget.md old mode 100644 new mode 100755 index 566635adc..af40c3d06 --- a/PowerShell/JumpCloud Module/Docs/Get-JCCommandTarget.md +++ b/PowerShell/JumpCloud Module/Docs/Get-JCCommandTarget.md @@ -40,6 +40,7 @@ Get-JCCommandTarget -CommandID '5a99777710p3690onylo3e1g' -Groups ``` Retrieves the JumpCloud system group targets that are associated the JumpCloud command with the Command ID '5a99777710p3690onylo3e1g' + ## PARAMETERS ### -CommandID diff --git a/PowerShell/JumpCloud Module/Docs/Get-JCSystem.md b/PowerShell/JumpCloud Module/Docs/Get-JCSystem.md index eecb6d645..0677f86ef 100644 --- a/PowerShell/JumpCloud Module/Docs/Get-JCSystem.md +++ b/PowerShell/JumpCloud Module/Docs/Get-JCSystem.md @@ -24,7 +24,7 @@ Get-JCSystem [[-hostname] ] [-displayName ] [-version ] ### ByID ``` -Get-JCSystem -SystemID -dateFilter -date [] +Get-JCSystem -SystemID [-SystemFDEKey] -dateFilter -date [] ``` ## DESCRIPTION @@ -394,6 +394,21 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -SystemFDEKey +A switch parameter to reveal the SystemFDEKey + +```yaml +Type: SwitchParameter +Parameter Sets: ByID +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +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). diff --git a/PowerShell/JumpCloud Module/Docs/Get-JCSystemInsights.md b/PowerShell/JumpCloud Module/Docs/Get-JCSystemInsights.md new file mode 100644 index 000000000..3cc9b1f3a --- /dev/null +++ b/PowerShell/JumpCloud Module/Docs/Get-JCSystemInsights.md @@ -0,0 +1,228 @@ +--- +external help file: JumpCloud-help.xml +Module Name: JumpCloud +online version: https://github.com/TheJumpCloud/support/wiki/Get-JCSystemInsights +schema: 2.0.0 +--- + +# Get-JCSystemInsights + +## SYNOPSIS +JumpCloud's System Insights feature provides admins with the ability to easily interrogate their +fleet of systems to find important pieces of information. Using this function you +can easily gather heightened levels of information from your fleet of JumpCloud managed +systems. + +## SYNTAX + +### Default +``` +Get-JCSystemInsights -Table [-Fields ] [-Filter ] [-Limit ] + [-Paginate ] [-Skip ] [] +``` + +### ById +``` +Get-JCSystemInsights -Table [-Fields ] [-Filter ] -Id [-Limit ] + [-Paginate ] [-Skip ] [] +``` + +### ByName +``` +Get-JCSystemInsights -Table [-Fields ] [-Filter ] [-Limit ] -Name + [-Paginate ] [-Skip ] [] +``` + +### ByValue +``` +Get-JCSystemInsights -Table [-Fields ] [-Filter ] [-Limit ] + [-Paginate ] [-Skip ] [] +``` + +## DESCRIPTION +Using Get-JCSystemInsights will allow you to easily query JumpCloud's RESTful API to return information from your fleet of JumpCloud managed +systems. + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> Get-JCSystemInsights -Table:('os_version'); +``` + +Return os_version data for all systems that have system insights enabled. + +### Example 2 +```powershell +PS C:\> Get-JCSystemInsights -Table:('os_version') -Id:('5d0917420905f70e36e3c0d3'); +``` + +Return os_version data for a system with a specified id. + +### Example 3 +```powershell +PS C:\> Get-JCSystemInsights -Table:('os_version') -Id:('5d0917420905f70e36e3c0d3', '5d0bc68b8e41442ccd10254a'); +``` + +Return os_version data for systems with specific ids. + +### Example 4 +```powershell +PS C:\> Get-JCSystemInsights -Table:('os_version') -Name:('MacBook-Pro.local_TEST'); +``` + +Return os_version data for a system with a specified name. + +### Example 5 +```powershell +PS C:\> Get-JCSystemInsights -Table:('os_version') -Name:('MacBook-Pro.local_TEST', 'Holly-Flax-Mac.local_TEST'); +``` + +Return os_version data for systems with specific names. + +### Example 6 +```powershell +PS C:\> Get-JCSystemInsights -Table users -Filter username:eq:jcadmin +``` + +Filters the users table for any system with the username jcadmin. + +## PARAMETERS + +### -Fields +An array of the fields/properties/columns you want to return from the search. + +```yaml +Type: Array +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Filter +Filters to narrow down search. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Id +The unique id of the object. + +```yaml +Type: String[] +Parameter Sets: ById +Aliases: _id + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Limit +The number of items you want to return per API call. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Name +The name of the object. + +```yaml +Type: String[] +Parameter Sets: ByName +Aliases: displayName + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Skip +Ignores the specified number of objects and then gets the remaining objects. +Enter the number of objects to skip. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Table +The SystemInsights table to query against. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: +Accepted values: apps, browser_plugins, chrome_extensions, disk_encryption, firefox_addons, groups, interface_addresses, mounts, os_version, safari_extensions, system_info, users + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Paginate +Whether or not you want to paginate through the results. + +```yaml +Type: Boolean +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +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 + +### System.String +### System.Array +### System.String[] +### System.Int32 +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS diff --git a/PowerShell/JumpCloud Module/Docs/Import-JCUsersFromCSV.md b/PowerShell/JumpCloud Module/Docs/Import-JCUsersFromCSV.md old mode 100644 new mode 100755 index 38b83c570..2c9ff9ee0 --- a/PowerShell/JumpCloud Module/Docs/Import-JCUsersFromCSV.md +++ b/PowerShell/JumpCloud Module/Docs/Import-JCUsersFromCSV.md @@ -30,7 +30,7 @@ During import a JumpCloud administrator can ensure the import is working by watc ## EXAMPLES -### Video Tutorials +### Video Tutorials [Basic User Import](https://youtu.be/WSE5_uGYcIc) @@ -56,6 +56,7 @@ PS C:\> Import-JCUsersFromCSV -CSVFilePath \users\cclemons\JCUserImport_11-16-20 ``` Uses the 'Force' paramter to skip the GUI and data validation and imports users from the file '\users\cclemons\JCUserImport_11-16-2017.csv' + ## PARAMETERS ### -CSVFilePath diff --git a/PowerShell/JumpCloud Module/Docs/New-JCImportTemplate.md b/PowerShell/JumpCloud Module/Docs/New-JCImportTemplate.md old mode 100644 new mode 100755 index ad2975576..7364b9f56 --- a/PowerShell/JumpCloud Module/Docs/New-JCImportTemplate.md +++ b/PowerShell/JumpCloud Module/Docs/New-JCImportTemplate.md @@ -22,7 +22,7 @@ If users wish to bind users to existing JumpCloud systems the function will also ## EXAMPLES -### Video Tutorials +### Video Tutorials [Basic User Import](https://youtu.be/WSE5_uGYcIc) diff --git a/PowerShell/JumpCloud Module/Docs/Remove-JCAssociation.md b/PowerShell/JumpCloud Module/Docs/Remove-JCAssociation.md index 87832b089..127003cae 100644 --- a/PowerShell/JumpCloud Module/Docs/Remove-JCAssociation.md +++ b/PowerShell/JumpCloud Module/Docs/Remove-JCAssociation.md @@ -14,14 +14,23 @@ Remove an association between two object within the JumpCloud console. ### ById (Default) ``` -Remove-JCAssociation [-Type] [-Force] [-Id] [-TargetType] [[-TargetId] ] - [[-TargetName] ] [] +Remove-JCAssociation [-Type] [-Force] [-Fields ] [-Filter ] [-Id] + [-Limit ] [-Paginate ] [-Skip ] [[-TargetId] ] [[-TargetName] ] + [[-TargetType] ] [] ``` ### ByName ``` -Remove-JCAssociation [-Type] [-Force] [-Name] [-TargetType] - [[-TargetId] ] [[-TargetName] ] [] +Remove-JCAssociation [-Type] [-Force] [-Fields ] [-Filter ] [-Limit ] + [-Name] [-Paginate ] [-Skip ] [[-TargetId] ] [[-TargetName] ] + [[-TargetType] ] [] +``` + +### ByValue +``` +Remove-JCAssociation [-Type] [-Force] [-Fields ] [-Filter ] [-Limit ] + [-Paginate ] [-Skip ] [[-TargetId] ] [[-TargetName] ] + [[-TargetType] ] [] ``` ## DESCRIPTION @@ -81,7 +90,7 @@ The name of the object. ```yaml Type: String[] Parameter Sets: ByName -Aliases: domain, displayName, username +Aliases: displayName, username Required: True Position: 4 @@ -129,7 +138,7 @@ Parameter Sets: (All) Aliases: TargetSingular Accepted values: user, user_group, system, system_group, policy, command, application, g_suite, ldap_server, office_365, radius_server -Required: True +Required: False Position: 5 Default value: None Accept pipeline input: True (ByPropertyName) @@ -152,6 +161,81 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -Fields +An array of the fields/properties/columns you want to return from the search. + +```yaml +Type: Array +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Filter +Filters to narrow down search. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Limit +The number of items you want to return per API call. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Skip +Ignores the specified number of objects and then gets the remaining objects. Enter the number of objects to skip. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -Paginate +Whether or not you want to paginate through the results. + +```yaml +Type: Boolean +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +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). diff --git a/PowerShell/JumpCloud Module/Docs/Remove-JCCommand.md b/PowerShell/JumpCloud Module/Docs/Remove-JCCommand.md old mode 100644 new mode 100755 index bd0a8f509..75204c096 --- a/PowerShell/JumpCloud Module/Docs/Remove-JCCommand.md +++ b/PowerShell/JumpCloud Module/Docs/Remove-JCCommand.md @@ -40,6 +40,7 @@ PS C:\> Remove-JCCommand -CommandID 5j09o6f23dan6f4n035601d5 -Force ``` Removes the JumpCloud Command with a CommandID of '5j09o6f23dan6f4n035601d5'. A warning message will not be presented to confirm this operation because the '-Force' parameter is used. + ## PARAMETERS ### -CommandID diff --git a/PowerShell/JumpCloud Module/Docs/Remove-JCCommandResult.md b/PowerShell/JumpCloud Module/Docs/Remove-JCCommandResult.md old mode 100644 new mode 100755 index 72312786b..15301ce44 --- a/PowerShell/JumpCloud Module/Docs/Remove-JCCommandResult.md +++ b/PowerShell/JumpCloud Module/Docs/Remove-JCCommandResult.md @@ -54,6 +54,7 @@ PS C:\> Get-JCCommandResult | Where-Object {$_.requestTime -GT (Get-Date).AddHou ``` Removes all JumpCloud commands that were run within the last hour and that had an exitCode of '0' using the -Force Parameter. Note an exitCode of zero generally represents a successful run of a command. This command removes all success Commands Results run in the past hour. + ## PARAMETERS ### -CommandResultID diff --git a/PowerShell/JumpCloud Module/Docs/Remove-JCCommandTarget.md b/PowerShell/JumpCloud Module/Docs/Remove-JCCommandTarget.md old mode 100644 new mode 100755 index 1cde8793b..39e44683a --- a/PowerShell/JumpCloud Module/Docs/Remove-JCCommandTarget.md +++ b/PowerShell/JumpCloud Module/Docs/Remove-JCCommandTarget.md @@ -52,6 +52,7 @@ Remove-JCCommandTarget -CommandID 5b99777710a3690ssisr3a1w -GroupID 5j03458a232z ``` Removes the JumpCloud system group with the GroupID '5j03458a232z115210z66913' and the systems within this group from the target list for the JumpCloud command with command ID '5b99777710a3690ssisr3a1w' + ## PARAMETERS ### -CommandID diff --git a/PowerShell/JumpCloud Module/Docs/Remove-JCRadiusReplyAttribute.md b/PowerShell/JumpCloud Module/Docs/Remove-JCRadiusReplyAttribute.md index 6abded5cb..c87accdb4 100644 --- a/PowerShell/JumpCloud Module/Docs/Remove-JCRadiusReplyAttribute.md +++ b/PowerShell/JumpCloud Module/Docs/Remove-JCRadiusReplyAttribute.md @@ -37,6 +37,7 @@ Remove-JCRadiusReplyAttribute -GroupName BoulderOffice -AttributeName "Session-T ``` Removes attributes with the name "Session-Timeout", "Termination-Action" from the target user group 'BoulderOffice'. To remove multiple attributes at one time separate the attribute names with commas. + ## PARAMETERS ### -All diff --git a/PowerShell/JumpCloud Module/Docs/Remove-JCSystem.md b/PowerShell/JumpCloud Module/Docs/Remove-JCSystem.md index 61486ebdb..f05ceef08 100644 --- a/PowerShell/JumpCloud Module/Docs/Remove-JCSystem.md +++ b/PowerShell/JumpCloud Module/Docs/Remove-JCSystem.md @@ -43,7 +43,7 @@ Removes the JumpCloud System with SystemID '5n0795a712704la4eve154r' using the - ### Example 3 ```powershell - Get-JCSystem | Where-Object lastContact -lT (Get-Date).AddDays(-30).ToString('yyy-MM-ddTHH:MM:ss') | Remove-JCSystem +Get-JCSystem | Where-Object lastContact -lT (Get-Date).AddDays(-30).ToString('yyy-MM-ddTHH:MM:ss') | Remove-JCSystem ``` Removes all JumpCloud Systems that have a lastContact date greater then 30 days. A warning message will be presented to confirm each operation. @@ -58,7 +58,7 @@ Removes all JumpCloud Systems that have a displayName like 'Server10'. A warning ### Example 5 ```PowerShell -Get-JCSystem -displayName System101 -returnProperties lastContact | Sort-Object lastContact -Descending | Select * -Skip 1 | Remove-JCSystem -force +Get-JCSystem -displayName System101 -returnProperties lastContact | Sort-Object lastContact -Descending | Select * -Skip 1 | Remove-JCSystem -force ``` Removes all but the last system to contact JumpCloud with the display name 'System101'. This can be used to clean up duplicate systems that may have the same name by replacing 'System101' with the name of the system that contains duplicates. diff --git a/PowerShell/JumpCloud Module/Docs/Remove-JCSystemGroup.md b/PowerShell/JumpCloud Module/Docs/Remove-JCSystemGroup.md index 77d005bcd..222676fa4 100644 --- a/PowerShell/JumpCloud Module/Docs/Remove-JCSystemGroup.md +++ b/PowerShell/JumpCloud Module/Docs/Remove-JCSystemGroup.md @@ -40,6 +40,7 @@ PS C:\> Remove-JCSystemGroup -GroupName 'On Prem Systems' -Force ``` Removes the JumpCloud System Group with the name 'On Prem Systems' using the -Force Parameter. A warning message will not be presented to confirm the operation. + ## PARAMETERS ### -GroupName diff --git a/PowerShell/JumpCloud Module/Docs/Remove-JCSystemGroupMember.md b/PowerShell/JumpCloud Module/Docs/Remove-JCSystemGroupMember.md index fecbb8aec..b9a19d5fe 100644 --- a/PowerShell/JumpCloud Module/Docs/Remove-JCSystemGroupMember.md +++ b/PowerShell/JumpCloud Module/Docs/Remove-JCSystemGroupMember.md @@ -48,6 +48,7 @@ Get-JCSystem | Where-Object active -EQ $false | Remove-JCSystemGroupMember -Grou ``` Removes all inactive systems from the System Group 'Active Systems' + ## PARAMETERS ### -ByID diff --git a/PowerShell/JumpCloud Module/Docs/Remove-JCSystemUser.md b/PowerShell/JumpCloud Module/Docs/Remove-JCSystemUser.md index 2819405ef..b840a46d8 100644 --- a/PowerShell/JumpCloud Module/Docs/Remove-JCSystemUser.md +++ b/PowerShell/JumpCloud Module/Docs/Remove-JCSystemUser.md @@ -61,6 +61,7 @@ PS C:\> Get-JCSystemUser -SystemID 5a0795nnie7127f4ev2erb154a | Remove-JCSystemU ``` Removes all JumpCloud users bound directly to the System with a System ID of '5a0795nnie7127f4ev2erb154a' using Parameter binding and the pipeline. A warning message will not be displayed to confirm each remove operation because of the presence of the -Force Parameter. + ## PARAMETERS ### -SystemID diff --git a/PowerShell/JumpCloud Module/Docs/Remove-JCUser.md b/PowerShell/JumpCloud Module/Docs/Remove-JCUser.md index a6390f859..62a4bab6f 100644 --- a/PowerShell/JumpCloud Module/Docs/Remove-JCUser.md +++ b/PowerShell/JumpCloud Module/Docs/Remove-JCUser.md @@ -40,6 +40,7 @@ PS C:\> Remove-JCUser cclemons -Force ``` Removes the JumpCloud User with Username 'cclemons' using the -Force Parameter. A warning message will not be presented to confirm this operation. + ## PARAMETERS ### -ByID diff --git a/PowerShell/JumpCloud Module/Docs/Remove-JCUserGroup.md b/PowerShell/JumpCloud Module/Docs/Remove-JCUserGroup.md index a7dae83bf..8b8e62334 100644 --- a/PowerShell/JumpCloud Module/Docs/Remove-JCUserGroup.md +++ b/PowerShell/JumpCloud Module/Docs/Remove-JCUserGroup.md @@ -40,6 +40,7 @@ PS C:\> Remove-JCUserGroup -GroupName 'The Band' -Force ``` Removes the JumpCloud User Group with the name 'The Band' using the -Force Parameter. A warning message will not be presented to confirm the operation. + ## PARAMETERS ### -GroupName diff --git a/PowerShell/JumpCloud Module/Docs/Remove-JCUserGroupMember.md b/PowerShell/JumpCloud Module/Docs/Remove-JCUserGroupMember.md index b54a413a0..38745c620 100644 --- a/PowerShell/JumpCloud Module/Docs/Remove-JCUserGroupMember.md +++ b/PowerShell/JumpCloud Module/Docs/Remove-JCUserGroupMember.md @@ -55,6 +55,7 @@ Get-JCUser | Select-Object username, @{name='Attribute Value'; expression={$_.at ``` Removes all JumpCloud users with a custom attribute value which contains 'Marketing' from the JumpCloud User Group 'Sales'. Note that to access the value of a nested property you must use Select-Object to access the nested property. In this example a calculated property is also used. + ## PARAMETERS ### -ByID diff --git a/PowerShell/JumpCloud Module/Docs/Send-JCPasswordReset.md b/PowerShell/JumpCloud Module/Docs/Send-JCPasswordReset.md index 3c0c2d7ca..a455a7a33 100644 --- a/PowerShell/JumpCloud Module/Docs/Send-JCPasswordReset.md +++ b/PowerShell/JumpCloud Module/Docs/Send-JCPasswordReset.md @@ -55,6 +55,7 @@ Get-JCUser -activated $false -filterDateProperty created -dateFilter after -date ``` Sends an activation email to all JumpCloud users who are in an inactive state and were created in the last seven days. Users that are inactive have not yet set their JumpCloud user passwords. + ## PARAMETERS ### -UserID diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCCommand.md b/PowerShell/JumpCloud Module/Docs/Set-JCCommand.md index 0b053b7d3..bfb9bd34b 100644 --- a/PowerShell/JumpCloud Module/Docs/Set-JCCommand.md +++ b/PowerShell/JumpCloud Module/Docs/Set-JCCommand.md @@ -35,6 +35,7 @@ Set-JCCommand -CommandID 5g6o3lf95r1485193o8cks6 -name "Windows - Get Windows Ev ``` Updates the 'name' of command with CommandID '5g6o3lf95r1485193o8cks6' to "Windows - Get Windows Event Log". + ## PARAMETERS ### -CommandID diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCSystem.md b/PowerShell/JumpCloud Module/Docs/Set-JCSystem.md index 12fa94aea..8a24244ca 100644 --- a/PowerShell/JumpCloud Module/Docs/Set-JCSystem.md +++ b/PowerShell/JumpCloud Module/Docs/Set-JCSystem.md @@ -36,6 +36,7 @@ PS C:\> Get-JCSystem | Where-Object os -Like *Mac* | Set-JCSystem -allowMultiFac ``` This example updates all Systems with an operating system like 'Mac' and allows for MFA login. + ## PARAMETERS ### -SystemID diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCSystemUser.md b/PowerShell/JumpCloud Module/Docs/Set-JCSystemUser.md index 7c367aca1..7087da516 100644 --- a/PowerShell/JumpCloud Module/Docs/Set-JCSystemUser.md +++ b/PowerShell/JumpCloud Module/Docs/Set-JCSystemUser.md @@ -47,6 +47,7 @@ PS C:\> Get-JCSystemUser 5n0795a712704la4eve154r | Set-JCSystemUser -Administra ``` Gets all users bound to JumpCloud system with SystemID '5n0795a712704la4eve154r' and sets them as standard users. Note any users who have Global Administrator permissions would keep their Administrator permissions. To find users with Global Administrator permissions run the command: 'Get-JCUser | Where-Object sudo -EQ $true' + ## PARAMETERS ### -Administrator diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCUserGroupLDAP.md b/PowerShell/JumpCloud Module/Docs/Set-JCUserGroupLDAP.md index 660022f8a..766ad2af5 100644 --- a/PowerShell/JumpCloud Module/Docs/Set-JCUserGroupLDAP.md +++ b/PowerShell/JumpCloud Module/Docs/Set-JCUserGroupLDAP.md @@ -48,6 +48,7 @@ Get-JCGroup -Type User | Set-JCUserGroupLDAP -LDAPEnabled $true ``` This command users the 'Get-JCGroup -Type User' command to pass all JumpCloud user groups to the 'Set-JCUserGroupLDAP' command and enables JumpCloud LDAP for all user groups within a JumpCloud tenant. + ## PARAMETERS ### -GroupID diff --git a/PowerShell/JumpCloud Module/Docs/Update-JCUsersFromCSV.md b/PowerShell/JumpCloud Module/Docs/Update-JCUsersFromCSV.md index 83319e6e9..11eb0ba01 100644 --- a/PowerShell/JumpCloud Module/Docs/Update-JCUsersFromCSV.md +++ b/PowerShell/JumpCloud Module/Docs/Update-JCUsersFromCSV.md @@ -42,6 +42,7 @@ PS C:\> Update-JCUsersFromCSV ./JCUserUpdateImport_09-20-2018.csv -Force ``` Uses the 'Force' parameter to skip the GUI and data validation and update users from the file 'JCUserUpdateImport_09-20-2018.csv + ## PARAMETERS ### -CSVFilePath diff --git a/PowerShell/JumpCloud Module/JumpCloud.psd1 b/PowerShell/JumpCloud Module/JumpCloud.psd1 index 232cf907a..6b6e7083c 100755 Binary files a/PowerShell/JumpCloud Module/JumpCloud.psd1 and b/PowerShell/JumpCloud Module/JumpCloud.psd1 differ diff --git a/PowerShell/JumpCloud Module/Private/Association/Get-DynamicParamAssociation.ps1 b/PowerShell/JumpCloud Module/Private/Association/Get-DynamicParamAssociation.ps1 index 8fd9b231c..3d3be9f9f 100755 --- a/PowerShell/JumpCloud Module/Private/Association/Get-DynamicParamAssociation.ps1 +++ b/PowerShell/JumpCloud Module/Private/Association/Get-DynamicParamAssociation.ps1 @@ -1,218 +1,150 @@ Function Get-DynamicParamAssociation { - [CmdletBinding()] Param( - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)][ValidateNotNullOrEmpty()][ValidateSet('add', 'get', 'remove')][string]$Action - , [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, Position = 1, HelpMessage = 'The type of the object.')][ValidateNotNullOrEmpty()][ValidateSet('command', 'ldap_server', 'policy', 'application', 'radius_server', 'system_group', 'system', 'user_group', 'user', 'g_suite', 'office_365')][Alias('TypeNameSingular')][string]$Type - , [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, Position = 2, HelpMessage = 'Bypass user confirmation and ValidateSet when adding or removing associations.')][ValidateNotNullOrEmpty()][Switch]$Force + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)][ValidateNotNullOrEmpty()][ValidateSet('add', 'get', 'remove')][System.String]$Action + , [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = 'The type of the object.')][ValidateNotNullOrEmpty()][ValidateSet('command', 'ldap_server', 'policy', 'application', 'radius_server', 'system_group', 'system', 'user_group', 'user', 'g_suite', 'office_365')][Alias('TypeNameSingular')][System.String]$Type + , [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = 'Bypass user prompts and dynamic ValidateSet.')][ValidateNotNullOrEmpty()][Switch]$Force ) - # Define the new parameters - $Param_Id = @{ - 'Name' = 'Id'; - 'Type' = [System.String[]]; - 'Position' = 3; - 'ValueFromPipelineByPropertyName' = $true; - 'ValidateNotNullOrEmpty' = $true; - 'ParameterSets' = @('ById'); - 'HelpMessage' = 'The unique id of the object.'; - } - $Param_Name = @{ - 'Name' = 'Name'; - 'Type' = [System.String[]]; - 'Position' = 4; - 'ValueFromPipelineByPropertyName' = $true; - 'ValidateNotNullOrEmpty' = $true; - 'ParameterSets' = @('ByName'); - 'HelpMessage' = 'The name of the object.'; - } - $Param_TargetType = @{ - 'Name' = 'TargetType'; - 'Type' = [System.String[]]; - 'Position' = 5; - 'ValueFromPipelineByPropertyName' = $true; - 'ValidateNotNullOrEmpty' = $true; - 'Alias' = ('TargetSingular'); - 'HelpMessage' = 'The type of the target object.'; - } - $Param_associationType = @{ - 'Name' = 'associationType'; - 'Type' = [System.String[]]; - 'Position' = 6; - 'ValueFromPipelineByPropertyName' = $true; - 'ValidateSet' = @("direct", "direct`/indirect", "indirect"); - 'DontShow' = $true; - 'HelpMessage' = 'Used for piping only to determine type of association when coming from Add-JCAssociation or Remove-JCAssociation.'; - 'Mandatory' = $false; - } - $Param_Raw = @{ - 'Name' = 'Raw'; - 'Type' = [Switch]; - 'Position' = 7; - 'ValueFromPipelineByPropertyName' = $true; - 'DefaultValue' = $false; - 'DontShow' = $true; - 'HelpMessage' = 'Returns the raw and unedited output from the api endpoint.'; - } - $Param_Direct = @{ - 'Name' = 'Direct'; - 'Type' = [Switch]; - 'Position' = 8; - 'ValueFromPipelineByPropertyName' = $true; - 'DefaultValue' = $false; - 'HelpMessage' = 'Returns only "Direct" associations.'; - } - $Param_Indirect = @{ - 'Name' = 'Indirect'; - 'Type' = [Switch]; - 'Position' = 9; - 'ValueFromPipelineByPropertyName' = $true; - 'DefaultValue' = $false; - 'HelpMessage' = 'Returns only "Indirect" associations.'; - } - $Param_IncludeInfo = @{ - 'Name' = 'IncludeInfo'; - 'Type' = [Switch]; - 'Position' = 10; - 'ValueFromPipelineByPropertyName' = $true; - 'ParameterSets' = @('ById', 'ByName'); - 'DefaultValue' = $false; - 'HelpMessage' = 'Appends "Info" and "TargetInfo" properties to output.'; - } - $Param_IncludeNames = @{ - 'Name' = 'IncludeNames'; - 'Type' = [Switch]; - 'Position' = 11; - 'ValueFromPipelineByPropertyName' = $true; - 'ParameterSets' = @('ById', 'ByName'); - 'DefaultValue' = $false; - 'HelpMessage' = 'Appends "Name" and "TargetName" properties to output.'; - } - $Param_IncludeVisualPath = @{ - 'Name' = 'IncludeVisualPath'; - 'Type' = [Switch]; - 'Position' = 12; - 'ValueFromPipelineByPropertyName' = $true; - 'ParameterSets' = @('ById', 'ByName'); - 'DefaultValue' = $false; - 'HelpMessage' = 'Appends "visualPathById", "visualPathByName", and "visualPathByType" properties to output.'; - } - $Param_TargetId = @{ - 'Name' = 'TargetId'; - 'Type' = [System.String]; - 'Position' = 13; - 'ValueFromPipelineByPropertyName' = $true; - 'HelpMessage' = 'The unique id of the target object.'; - } - $Param_TargetName = @{ - 'Name' = 'TargetName'; - 'Type' = [System.String]; - 'Position' = 14; - 'ValueFromPipelineByPropertyName' = $true; - 'HelpMessage' = 'The name of the target object.'; - } - $Param_Attributes = @{ - 'Name' = 'Attributes'; - 'Type' = [System.Management.Automation.PSObject]; - 'Position' = 15; - 'ValueFromPipelineByPropertyName' = $true; - 'Alias' = 'compiledAttributes'; - 'HelpMessage' = 'Add attributes that define the association such as if they are an admin.'; - } - # Get type list - $JCTypes = Get-JCType | Where-Object { $_.Category -eq 'JumpCloud' }; - # Add properties to the parameters based upon the setup of the org for performance considerations - If (!($Action -and $Type)) - { - $Param_Id.Add('Mandatory', $true) - $Param_Name.Add('Mandatory', $true) - $Param_TargetType.Add('Mandatory', $true) - $Param_Id.Add('Alias', ($JCTypes.ById | Where-Object { $_ -ne 'Id' } | Select-Object -Unique)) - $Param_Name.Add('Alias', ($JCTypes.ByName | Where-Object { $_ -ne 'Name' } | Select-Object -Unique)) - $Param_TargetType.Add('ValidateSet', ($JCTypes.Targets.TargetSingular | Select-Object -Unique)) - } - Else + Begin { - # Determine if help files are being built - If ((Get-PSCallStack).Command -like '*MarkdownHelp') + $RuntimeParameterDictionary = If ($Type) { - $JCObjectCount = 999999 + Get-JCCommonParameters -Force:($Force) -Type:($Type); } Else { - # Get targets list - $JCTypes = $JCTypes | Where-Object { $_.TypeName.TypeNameSingular -eq $Type }; - # Get count of JCObject to determine if script should load dynamic parameters - $JCObjectCount = (Get-JCObject -Type:($Type) -ReturnCount).totalCount + Get-JCCommonParameters -Force:($Force); } - $Param_TargetType.Add('Mandatory', $false) - If ($JCObjectCount -ge 1 -and $JCObjectCount -le 300) + # Get type list + $JCType = If ($Type) { - # Get all objects of the specific type - $JCObject = Get-JCObject -Type:($Type); - $Param_Id.Add('Alias', ($JCObject.ById | Where-Object { $_ -ne 'Id' } | Select-Object -Unique)) - $Param_Name.Add('Alias', ($JCObject.ByName | Where-Object { $_ -ne 'Name' } | Select-Object -Unique)) - $Param_TargetType.Add('DefaultValue', ($JCObject.Targets.TargetSingular | Select-Object -Unique)) - $Param_TargetType.Add('ValidateSet', ($JCObject.Targets.TargetSingular | Select-Object -Unique)) - If ($JCObjectCount -eq 1) - { - # Don't require Id and Name to be passed through and set a default value - $Param_Id.Add('Mandatory', $false) - $Param_Name.Add('Mandatory', $false) - $Param_Id.Add('DefaultValue', $JCObject.($JCObject.ById)) - $Param_Name.Add('DefaultValue', $JCObject.($JCObject.ByName)) - } - Else - { - # Do populate validate set with list of items - $Param_Id.Add('Mandatory', $true) - $Param_Name.Add('Mandatory', $true) - If (!($Force)) - { - $Param_Id.Add('ValidateSet', @($JCObject.($JCObject.ById | Select-Object -Unique))) - $Param_Name.Add('ValidateSet', @($JCObject.($JCObject.ByName | Select-Object -Unique))) - } - } + Get-JCType -Type:($Type) | Where-Object { $_.Category -eq 'JumpCloud'}; } Else { - # Don't populate validate set - $Param_Id.Add('Mandatory', $true) - $Param_Name.Add('Mandatory', $true) - $Param_Id.Add('Alias', ($JCTypes.ById | Where-Object { $_ -ne 'Id' } | Select-Object -Unique)) - $Param_Name.Add('Alias', ($JCTypes.ByName | Where-Object { $_ -ne 'Name' } | Select-Object -Unique)) - $Param_TargetType.Add('ValidateSet', ($JCTypes.Targets.TargetSingular | Select-Object -Unique)) - $Param_TargetType.Add('DefaultValue', ($JCTypes.Targets.TargetSingular | Select-Object -Unique)) + Get-JCType | Where-Object { $_.Category -eq 'JumpCloud'}; } } - # Create the parameter array - $Params = @() - # Add parameters to array - $Params += $Param_Id - $Params += $Param_Name - $Params += $Param_TargetType - If ($Action -eq 'get') + Process { - $Params += $Param_Raw - $Params += $Param_Direct - $Params += $Param_Indirect - $Params += $Param_IncludeInfo - $Params += $Param_IncludeNames - $Params += $Param_IncludeVisualPath - } - If ($Action -in ('add', 'remove')) - { - $Params += $Param_TargetId - $Params += $Param_TargetName - $Params += $Param_associationType + # Define the new parameters + $Param_TargetType = @{ + 'Name' = 'TargetType'; + 'Type' = [System.String[]]; + 'Mandatory' = $false; + 'ValueFromPipelineByPropertyName' = $true; + 'ValidateNotNullOrEmpty' = $true; + 'Alias' = ('TargetSingular'); + 'HelpMessage' = 'The type of the target object.'; + 'ValidateSet' = $JCType.Targets.TargetSingular | Select-Object -Unique; + 'DefaultValue' = $JCType.Targets.TargetSingular | Select-Object -Unique; + } + $Param_associationType = @{ + 'Name' = 'associationType'; + 'Type' = [System.String[]]; + 'ValueFromPipelineByPropertyName' = $true; + 'ValidateSet' = @("direct", "direct`/indirect", "indirect"); + 'DontShow' = $true; + 'HelpMessage' = 'Used for piping only to determine type of association when coming from Add-JCAssociation or Remove-JCAssociation.'; + 'Mandatory' = $false; + } + $Param_Raw = @{ + 'Name' = 'Raw'; + 'Type' = [Switch]; + 'ValueFromPipelineByPropertyName' = $true; + 'DefaultValue' = $false; + 'DontShow' = $true; + 'HelpMessage' = 'Returns the raw and unedited output from the api endpoint.'; + } + $Param_Direct = @{ + 'Name' = 'Direct'; + 'Type' = [Switch]; + 'ValueFromPipelineByPropertyName' = $true; + 'DefaultValue' = $false; + 'HelpMessage' = 'Returns only "Direct" associations.'; + } + $Param_Indirect = @{ + 'Name' = 'Indirect'; + 'Type' = [Switch]; + 'ValueFromPipelineByPropertyName' = $true; + 'DefaultValue' = $false; + 'HelpMessage' = 'Returns only "Indirect" associations.'; + } + $Param_IncludeInfo = @{ + 'Name' = 'IncludeInfo'; + 'Type' = [Switch]; + 'ValueFromPipelineByPropertyName' = $true; + 'DefaultValue' = $false; + 'HelpMessage' = 'Appends "Info" and "TargetInfo" properties to output.'; + } + $Param_IncludeNames = @{ + 'Name' = 'IncludeNames'; + 'Type' = [Switch]; + 'ValueFromPipelineByPropertyName' = $true; + 'DefaultValue' = $false; + 'HelpMessage' = 'Appends "Name" and "TargetName" properties to output.'; + } + $Param_IncludeVisualPath = @{ + 'Name' = 'IncludeVisualPath'; + 'Type' = [Switch]; + 'ValueFromPipelineByPropertyName' = $true; + 'DefaultValue' = $false; + 'HelpMessage' = 'Appends "visualPathById", "visualPathByName", and "visualPathByType" properties to output.'; + } + $Param_TargetId = @{ + 'Name' = 'TargetId'; + 'Type' = [System.String]; + 'ValueFromPipelineByPropertyName' = $true; + 'HelpMessage' = 'The unique id of the target object.'; + } + $Param_TargetName = @{ + 'Name' = 'TargetName'; + 'Type' = [System.String]; + 'ValueFromPipelineByPropertyName' = $true; + 'HelpMessage' = 'The name of the target object.'; + } + $Param_Attributes = @{ + 'Name' = 'Attributes'; + 'Type' = [System.Management.Automation.PSObject]; + 'ValueFromPipelineByPropertyName' = $true; + 'Alias' = 'compiledAttributes'; + 'HelpMessage' = 'Add attributes that define the association such as if they are an admin.'; + } + # Build output + $ParamVarPrefix = 'Param_' + Get-Variable | Where-Object {$_.Name -like '*' + $ParamVarPrefix + '*'} | ForEach-Object { + # Add RuntimeDictionary to each parameter + $_.Value.Add('RuntimeParameterDictionary', $RuntimeParameterDictionary) + # Creating each parameter + $VarName = $_.Name + $VarValue = $_.Value + Try + { + If ($_.Name -eq 'Param_TargetType') + { + New-DynamicParameter @VarValue | Out-Null + } + If ($Action -eq 'get' -and $_.Name -in ('Param_Raw', 'Param_Direct', 'Param_Indirect', 'Param_IncludeInfo', 'Param_IncludeNames', 'Param_IncludeVisualPath')) + { + New-DynamicParameter @VarValue | Out-Null + } + ElseIf ($Action -in ('add', 'remove') -and $_.Name -in ('Param_TargetId', 'Param_TargetName', 'Param_associationType')) + { + New-DynamicParameter @VarValue | Out-Null + } + ElseIf ($Action -eq 'add' -and $_.Name -in ('Param_Attributes')) + { + New-DynamicParameter @VarValue | Out-Null + } + } + Catch + { + Write-Error -Message:('Unable to create dynamic parameter:"' + $VarName.Replace($ParamVarPrefix, '') + '"; Error:' + $Error) + } + } } - If ($Action -eq 'add') + End { - $Params += $Param_Attributes + Return $RuntimeParameterDictionary } - # Create new parameters - $RuntimeParameterDictionary = $Params | - ForEach-Object { New-Object -TypeName:('PSObject') -Property:($_) } | - New-DynamicParameter - # Return parameters - Return $RuntimeParameterDictionary } \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Private/Association/Invoke-JCAssociation.ps1 b/PowerShell/JumpCloud Module/Private/Association/Invoke-JCAssociation.ps1 index 21b16dc0e..48e3d2988 100755 --- a/PowerShell/JumpCloud Module/Private/Association/Invoke-JCAssociation.ps1 +++ b/PowerShell/JumpCloud Module/Private/Association/Invoke-JCAssociation.ps1 @@ -2,14 +2,14 @@ { [CmdletBinding(DefaultParameterSetName = 'ById')] Param( - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)][ValidateNotNullOrEmpty()][ValidateSet('add', 'get', 'remove')][string]$Action - , [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1, HelpMessage = 'The type of the object.')][ValidateNotNullOrEmpty()][ValidateSet('command', 'ldap_server', 'policy', 'application', 'radius_server', 'system_group', 'system', 'user_group', 'user', 'g_suite', 'office_365')][Alias('TypeNameSingular')][string]$Type - , [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, Position = 2, HelpMessage = 'Bypass user confirmation and ValidateSet when adding or removing associations.')][ValidateNotNullOrEmpty()][Switch]$Force + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)][ValidateNotNullOrEmpty()][ValidateSet('add', 'get', 'remove')][System.String]$Action + , [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = 'The type of the object.')][ValidateNotNullOrEmpty()][ValidateSet('command', 'ldap_server', 'policy', 'application', 'radius_server', 'system_group', 'system', 'user_group', 'user', 'g_suite', 'office_365')][Alias('TypeNameSingular')][System.String]$Type + , [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = 'Bypass user prompts and dynamic ValidateSet.')][ValidateNotNullOrEmpty()][Switch]$Force ) DynamicParam { # Build dynamic parameters - $RuntimeParameterDictionary = Get-DynamicParamAssociation @PsBoundParameters + $RuntimeParameterDictionary = Get-DynamicParamAssociation -Action:($Action) -Type:($Type) -Force:($true) Return $RuntimeParameterDictionary } Begin @@ -272,6 +272,7 @@ { If ($Results) { + # List values to hide in results $HiddenProperties = @('httpMetaData') Return Hide-ObjectProperty -Object:($Results) -HiddenProperties:($HiddenProperties) } diff --git a/PowerShell/JumpCloud Module/Private/DynamicParameters/Get-JCCommonParameters.ps1 b/PowerShell/JumpCloud Module/Private/DynamicParameters/Get-JCCommonParameters.ps1 new file mode 100644 index 000000000..873b1b41c --- /dev/null +++ b/PowerShell/JumpCloud Module/Private/DynamicParameters/Get-JCCommonParameters.ps1 @@ -0,0 +1,183 @@ +Function Get-JCCommonParameters +{ + Param( + [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = 'The RuntimeDefinedParameterDictionary to store variables.')][ValidateNotNullOrEmpty()][System.Management.Automation.RuntimeDefinedParameterDictionary]$RuntimeParameterDictionary = (New-Object -TypeName:([System.Management.Automation.RuntimeDefinedParameterDictionary])) + , [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = 'The type of the object.')][ValidateNotNullOrEmpty()][ValidateSet('command', 'ldap_server', 'policy', 'application', 'radius_server', 'system_group', 'system', 'user_group', 'user', 'g_suite', 'office_365')][Alias('TypeNameSingular')][System.String]$Type + , [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = 'Bypass user prompts and dynamic ValidateSet.')][ValidateNotNullOrEmpty()][Switch]$Force + ) + Begin + { + } + Process + { + # Get type list + $script:JCType = If ($Type) + { + Get-JCType -Type:($Type) | Where-Object { $_.Category -eq 'JumpCloud'}; + } + Else + { + Get-JCType | Where-Object { $_.Category -eq 'JumpCloud'}; + } + # Define the new parameters + $Param_Id = @{ + 'Name' = 'Id'; + 'Type' = [System.String[]]; + 'ValueFromPipelineByPropertyName' = $true; + 'ValidateNotNullOrEmpty' = $true; + 'ParameterSets' = @('ById'); + 'HelpMessage' = 'The unique id of the object.'; + 'Alias' = $JCType.ById | Where-Object { $_ -ne 'Id' } | Select-Object -Unique; + } + $Param_Name = @{ + 'Name' = 'Name'; + 'Type' = [System.String[]]; + 'ValueFromPipelineByPropertyName' = $true; + 'ValidateNotNullOrEmpty' = $true; + 'ParameterSets' = @('ByName'); + 'HelpMessage' = 'The name of the object.'; + 'Alias' = $JCType.ByName | Where-Object { $_ -ne 'Name' } | Select-Object -Unique; + } + $Param_SearchBy = @{ + 'Name' = 'SearchBy'; + 'Type' = [System.String]; + 'Mandatory' = $true; + 'ValueFromPipelineByPropertyName' = $true; + 'ValidateNotNullOrEmpty' = $true; + 'ParameterSets' = @('ByValue'); + 'ValidateSet' = @('ById', 'ByName'); + 'HelpMessage' = 'Specify how you want to search.'; + 'DontShow' = $true; + } + $Param_SearchByValue = @{ + 'Name' = 'SearchByValue'; + 'Type' = [System.String[]]; + 'Mandatory' = $true; + 'ValueFromPipelineByPropertyName' = $true; + 'ValidateNotNullOrEmpty' = $true; + 'ParameterSets' = @('ByValue'); + 'HelpMessage' = 'Specify the item which you want to search for. Supports wildcard searches using: *'; + 'DontShow' = $true; + } + $Param_Fields = @{ + 'Name' = 'Fields'; + 'Type' = [System.Array]; + 'ValueFromPipelineByPropertyName' = $true; + 'ValidateNotNullOrEmpty' = $true; + 'HelpMessage' = 'An array of the fields/properties/columns you want to return from the search.'; + } + $Param_Filter = @{ + 'Name' = 'Filter'; + 'Type' = [System.String]; + 'ValueFromPipelineByPropertyName' = $true; + 'ValidateNotNullOrEmpty' = $true; + 'HelpMessage' = 'Filters to narrow down search.'; + 'ValidateScript' = { + $FilterPattern = [regex]'.*?:.*?:.*?' + If ($_ -notmatch $FilterPattern) + { + Throw ('Invalid filter "' + $_ + '". Filter must match pattern: {PropertyName}:{Operator}:{Value} (' + $FilterPattern + ')') + } + Else + { + $FilterParts = $_ -split ':' + $FilterProperties = ((($JCType.ByName, $JCType.ById) + $JCType.SystemInsights.ByName + $JCType.SystemInsights.ById) | Select-Object -Unique) + $FilterOperators = $JCType.FilterOperators + $JCType.SystemInsights.FilterOperators | Select-Object -Unique + If ($FilterParts[0] -notin $FilterProperties) + { + Throw ('Invalid filter property provided "' + $FilterParts[0] + '". Accepted filter properties: "' + ($FilterProperties -join ', ') + '"') + } + If ($FilterParts[1] -notin $FilterOperators) + { + Throw ('Invalid filter operator provided "' + $FilterParts[1] + '". Accepted filter operators: "' + ($FilterOperators -join ', ') + '"') + } + $true + } + }; + } + $Param_Limit = @{ + 'Name' = 'Limit'; + 'Type' = [System.Int32]; + 'ValueFromPipelineByPropertyName' = $true; + 'ValidateRange' = (1, [int]::MaxValue); + 'DefaultValue' = $JCType.Limit | Select-Object -Unique; + 'HelpMessage' = 'The number of items you want to return per API call.'; + } + $Param_Skip = @{ + 'Name' = 'Skip'; + 'Type' = [System.Int32]; + 'ValueFromPipelineByPropertyName' = $true; + 'ValidateRange' = (0, [int]::MaxValue); + 'DefaultValue' = $JCType.Skip | Select-Object -Unique; + 'HelpMessage' = 'The number of items you want to skip over per API call.'; + } + $Param_Paginate = @{ + 'Name' = 'Paginate'; + 'Type' = [System.Boolean]; + 'ValueFromPipelineByPropertyName' = $true; + 'DefaultValue' = $JCType.Paginate | Select-Object -Unique; + 'HelpMessage' = 'Whether or not you want to paginate through the results.'; + } + # # Add conditional parameter settings + # If ($Type -and -not $Force) + # { + # # Determine if help files are being built + # If ((Get-PSCallStack).Command -like '*MarkdownHelp') + # { + # $JCObjectCount = 999999 + # } + # Else + # { + # # Get count of JCObject to determine if script should load dynamic parameters + # $JCObjectCount = (Get-JCObject -Type:($Type) -ReturnCount).totalCount + # } + # } + # If ($Type -and -not $Force -and $JCObjectCount -le 300) + # { + # # Populate DefaultValue and ValidateSets + # $JCObject = Get-JCObject -Type:($Type); + # $Param_Id.Add('DefaultValue', $JCObject.($JCObject.ById | Select-Object -Unique)); + # $Param_Name.Add('DefaultValue', $JCObject.($JCObject.ByName | Select-Object -Unique)); + # $Param_Id.Add('ValidateSet', @($JCObject.($JCObject.ById | Select-Object -Unique))); + # $Param_Name.Add('ValidateSet', @($JCObject.($JCObject.ByName | Select-Object -Unique))); + # If ($JCObjectCount -eq 1) + # { + # # Allow Id and Name to use the default value + # $Param_Id.Add('Mandatory', $false); + # $Param_Name.Add('Mandatory', $false); + # } + # ElseIf ($JCObjectCount -ge 1) + # { + # # Don't allow Id and Name to use the default value + # $Param_Id.Add('Mandatory', $true); + # $Param_Name.Add('Mandatory', $true); + # } + # } + # Else + # { + $Param_Id.Add('Mandatory', $true); + $Param_Name.Add('Mandatory', $true); + # } + # Build output + $ParamVarPrefix = 'Param_' + Get-Variable | Where-Object {$_.Name -like '*' + $ParamVarPrefix + '*'} | ForEach-Object { + # Add RuntimeDictionary to each parameter + $_.Value.Add('RuntimeParameterDictionary', $RuntimeParameterDictionary) + # Creating each parameter + $VarName = $_.Name + $VarValue = $_.Value + Try + { + New-DynamicParameter @VarValue | Out-Null + } + Catch + { + Write-Error -Message:('Unable to create dynamic parameter:"' + $VarName.Replace($ParamVarPrefix, '') + '"; Error:' + $Error) + } + } + } + End + { + Return $RuntimeParameterDictionary + } +} \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Private/HashFunctions/Get-Hash_employeeIdentifier_ID.ps1 b/PowerShell/JumpCloud Module/Private/HashFunctions/Get-Hash_employeeIdentifier_username.ps1 similarity index 100% rename from PowerShell/JumpCloud Module/Private/HashFunctions/Get-Hash_employeeIdentifier_ID.ps1 rename to PowerShell/JumpCloud Module/Private/HashFunctions/Get-Hash_employeeIdentifier_username.ps1 diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-FunctionReport.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-FunctionReport.ps1 new file mode 100755 index 000000000..7cd7a0b07 --- /dev/null +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-FunctionReport.ps1 @@ -0,0 +1,42 @@ +Function Get-FunctionReport +{ + Param([string[]]$Folder) + # Get a list of all functions in the current runspace + $CurrentFunctions = Get-ChildItem -Path:('function:') + # Load all function files from the module + $Files = Get-ChildItem -Path:($Folder) -Recurse | Where-Object { $_.Extension -eq '.ps1' } + # Loop through each function file + $FunctionList = ForEach ($File In $Files) + { + $FileFullName = $File.FullName + $FileName = $File.Name + $FileBaseName = $File.BaseName + # Parse the file and look for function syntax to identify functions + [regex]$Function_Regex = '(?<=^Function)(.*?)(?=$|\{|\()' + $FunctionRegexMatch = Get-Content -Path:($FileFullName) | Select-String -Pattern:($Function_Regex) #| Where {-not [System.String]::IsNullOrEmpty($_)} + $FunctionRegexMatchObject = $FunctionRegexMatch | Select-Object LineNumber, Line, @{Name = 'MatchValue'; Expression = { ($_.Matches.Value).Trim() } } + # Load the function into the current runspace + . ($FileFullName) + # Regather a list of all functions in the current runspace and filter out the functions that existed before loading the function script + $ScriptFunctions = Get-ChildItem -Path:('function:') | Where-Object { $CurrentFunctions -notcontains $_ } + # $ScriptFunctions | Select * + # Remove the function from the current runspace + $ScriptFunctions | ForEach-Object { Remove-Item -Path:('function:\' + $_) } + # $ScriptFunctions.Visibility + $FolderLocation = If ($FileFullName -like '*Private*') { 'Private' }ElseIf ($FileFullName -like '*Public*') { 'Public' } Else { 'Unknown' } + # Build dataset to perform validations against + [PSCustomObject]@{ + # 'FullName' = $FileFullName; + 'FileName' = $FileName; + 'LineNumber' = $FunctionRegexMatchObject.LineNumber + 'FileBaseName' = $FileBaseName; + 'Function' = $ScriptFunctions.Name + 'MatchValue' = $FunctionRegexMatchObject.MatchValue + 'Line' = $FunctionRegexMatchObject.Line + 'Verb' = $ScriptFunctions.Verb + 'Noun' = $ScriptFunctions.Noun + 'FolderLocation' = $FolderLocation + } + } + Return $FunctionList +} \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCObject.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCObject.ps1 index 6837dd9d5..4ca7a116c 100755 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCObject.ps1 +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Get-JCObject.ps1 @@ -1,22 +1,26 @@ Function Get-JCObject { [CmdletBinding(DefaultParameterSetName = 'Default')] - Param() + Param( + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0, HelpMessage = 'The type of the object.')][ValidateNotNullOrEmpty()][ValidateSet('command', 'ldap_server', 'policy', 'application', 'radius_server', 'system_group', 'system', 'user_group', 'user', 'g_suite', 'office_365')][Alias('TypeNameSingular')][System.String]$Type + ) DynamicParam { - $JCTypes = Get-JCType - # Build parameter array - $RuntimeParameterDictionary = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary - New-DynamicParameter -Name:('Type') -Type:([System.String]) -Mandatory -Position:(0) -ValueFromPipelineByPropertyName -ValidateNotNullOrEmpty -ValidateSet:($JCTypes.TypeName.TypeNameSingular) -RuntimeParameterDictionary:($RuntimeParameterDictionary) | Out-Null - New-DynamicParameter -Name:('Id') -Type([System.String[]]) -Mandatory -Position(1) -ValueFromPipelineByPropertyName -ValidateNotNullOrEmpty -ParameterSets(@('ById')) -Alias:(($JCTypes.ById) | Where-Object {$_ -ne 'Id'} | Select-Object -Unique) -RuntimeParameterDictionary:($RuntimeParameterDictionary) | Out-Null - New-DynamicParameter -Name:('Name') -Type([System.String[]]) -Mandatory -Position(1) -ValueFromPipelineByPropertyName -ValidateNotNullOrEmpty -ParameterSets:(@('ByName')) -Alias:(($JCTypes.ByName) | Where-Object {$_ -ne 'Name'} | Select-Object -Unique) -RuntimeParameterDictionary:($RuntimeParameterDictionary) | Out-Null - New-DynamicParameter -Name:('SearchBy') -Type:([System.String]) -Mandatory -Position:(1) -ValueFromPipelineByPropertyName -ValidateNotNullOrEmpty -ParameterSets:('ByValue') -ValidateSet:(@('ById', 'ByName')) -RuntimeParameterDictionary:($RuntimeParameterDictionary) | Out-Null - New-DynamicParameter -Name:('SearchByValue') -Type:([System.String[]]) -Mandatory -Position:(2) -ValueFromPipelineByPropertyName -ValidateNotNullOrEmpty -ParameterSets:('ByValue') -HelpMessage:('Specify the item which you want to search for. Supports wildcard searches using: *') -RuntimeParameterDictionary:($RuntimeParameterDictionary) | Out-Null - New-DynamicParameter -Name:('Fields') -Type:([System.Array]) -Position:(3) -ValueFromPipelineByPropertyName -ValidateNotNullOrEmpty -HelpMessage:('An array of the fields/properties/columns you want to return from the search.') -RuntimeParameterDictionary:($RuntimeParameterDictionary) | Out-Null - New-DynamicParameter -Name:('Limit') -Type:([System.Int32]) -Position:(4) -ValueFromPipelineByPropertyName -ValidateRange:(1, [int]::MaxValue) -RuntimeParameterDictionary:($RuntimeParameterDictionary) | Out-Null - New-DynamicParameter -Name:('Skip') -Type:([System.Int32]) -Position:(5) -ValueFromPipelineByPropertyName -ValidateRange:(1, [int]::MaxValue) -RuntimeParameterDictionary:($RuntimeParameterDictionary) | Out-Null - New-DynamicParameter -Name:('ReturnHashTable') -Type:([switch]) -Position:(6) -ValueFromPipelineByPropertyName -RuntimeParameterDictionary:($RuntimeParameterDictionary) -DefaultValue:($false) | Out-Null - New-DynamicParameter -Name:('ReturnCount') -Type:([switch]) -Position:(7) -ValueFromPipelineByPropertyName -RuntimeParameterDictionary:($RuntimeParameterDictionary) -DefaultValue:($false) | Out-Null + $JCType = Get-JCType | Where-Object { $_.TypeName.TypeNameSingular -eq $Type }; + $RuntimeParameterDictionary = If ($Type) + { + Get-JCCommonParameters -Force:($true) -Type:($Type); + } + Else + { + Get-JCCommonParameters -Force:($true); + } + If ('SystemInsights' -in $JCType.PSObject.Properties.Name -or (Get-PSCallStack).Command -like '*MarkdownHelp') + { + New-DynamicParameter -Name:('Table') -Type:([System.String]) -ValueFromPipelineByPropertyName -ValidateNotNullOrEmpty -ValidateSet:($JCType.SystemInsights.Table) -HelpMessage:('The SystemInsights table to query against.') -RuntimeParameterDictionary:($RuntimeParameterDictionary) | Out-Null + } + New-DynamicParameter -Name:('ReturnHashTable') -Type:([switch]) -ValueFromPipelineByPropertyName -RuntimeParameterDictionary:($RuntimeParameterDictionary) -DefaultValue:($false) | Out-Null + New-DynamicParameter -Name:('ReturnCount') -Type:([switch]) -ValueFromPipelineByPropertyName -DefaultValue:($false) -RuntimeParameterDictionary:($RuntimeParameterDictionary) | Out-Null Return $RuntimeParameterDictionary } Begin @@ -31,215 +35,276 @@ Function Get-JCObject Invoke-Command -ScriptBlock:($ScriptBlock_DefaultDynamicParamProcess) -ArgumentList:($PsBoundParameters, $PSCmdlet, $RuntimeParameterDictionary) -NoNewScope Try { - # Identify the command type to run to get the object for the specified item - $JCTypeItem = $JCTypes | Where-Object { $Type -in $_.TypeName.TypeNameSingular } - If ($JCTypeItem) + If ($JCType) { - $TypeName = $JCTypeItem.TypeName - $TypeNameSingular = $TypeName.TypeNameSingular - $TypeNamePlural = $TypeName.TypeNamePlural - $Targets = $JCTypeItem.Targets - $TargetSingular = $Targets.TargetSingular - $TargetPlural = $Targets.TargetPlural - $Url = $JCTypeItem.Url - $Method = $JCTypeItem.Method - $ById = $JCTypeItem.ById - $ByName = $JCTypeItem.ByName - $Paginate = $JCTypeItem.Paginate - $SupportRegexFilter = $JCTypeItem.SupportRegexFilter - $Limit = $JCTypeItem.Limit + # Set the location base location in the json config and elect the specific system insights table + $JCType = If ($PsBoundParameters.Table -and $PSCmdlet.ParameterSetName -ne 'ByName') + { + $JCType.SystemInsights | Where-Object {$_.Table -eq $PsBoundParameters.Table} + } + Else + { + $JCType + } $UrlObject = @() - # If searching ByValue add filters to query string and body. # Hacky logic to get g_suite and office_365 directories - If ($PSCmdlet.ParameterSetName -eq 'Default' -or $TypeNameSingular -in ('g_suite', 'office_365')) + # If searching ByValue add filters to query string and body. + If ($PSCmdlet.ParameterSetName -eq 'ById') { - $UrlObject += [PSCustomObject]@{ - 'Url' = $Url; - 'Body' = $null; - 'SearchByValue' = $null; + $SearchBy = 'ById' + $SearchByValue = $Id + $PropertyIdentifier = $JCType.ById + } + ElseIf ($PSCmdlet.ParameterSetName -eq 'ByName') + { + $SearchBy = 'ByName' + $SearchByValue = $Name + $PropertyIdentifier = $JCType.ByName + } + ElseIf ($PSCmdlet.ParameterSetName -eq 'ByValue') + { + $SearchBy = $SearchBy + $SearchByValue = $SearchByValue + $PropertyIdentifier = Switch ($SearchBy) + { + 'ById' { $JCType.ById }; + 'ByName' { $JCType.ByName }; } } - Else + ElseIf ($PSCmdlet.ParameterSetName -eq 'Default') { - If ($PSCmdlet.ParameterSetName -eq 'ById') + # Populate url variables + $UrlOut = If ($SearchBy -eq 'ById') { - $SearchBy = 'ById' - $SearchByValue = $Id - $PropertyIdentifier = $JCTypeItem.ById + If ($JCType.Url.variables) + { + ($JCType.Url.Item).Replace($JCType.Url.variables, $SearchByValue) + } + Else + { + $JCType.Url.Item + } } - ElseIf ($PSCmdlet.ParameterSetName -eq 'ByName') + Else { - $SearchBy = 'ByName' - $SearchByValue = $Name - $PropertyIdentifier = $JCTypeItem.ByName + $JCType.Url.List } - ElseIf ($PSCmdlet.ParameterSetName -eq 'ByValue') + # Populate query string filter + If ($Filter) { - $SearchBy = $SearchBy - $SearchByValue = $SearchByValue - $PropertyIdentifier = Switch ($SearchBy) - { - 'ById' { $JCTypeItem.ById }; - 'ByName' { $JCTypeItem.ByName }; - } + $QueryString = '?filter=' + $Filter + } + # Build final body and url + $UrlObject += [PSCustomObject]@{ + 'Type' = $Type; + 'SearchBy' = $null; + 'SearchByValueItem' = $null; + 'UrlPath' = $UrlOut; + 'QueryString' = $QueryString; + 'Body' = $null; + 'UrlFull' = $JCUrlBasePath + $UrlOut + $QueryString; } - ForEach ($SearchByValueItem In $SearchByValue) + } + Else + { + Write-Error ('Unknown $PSCmdlet.ParameterSetName: ' + $PSCmdlet.ParameterSetName) + } + # Loop through each item passed in and build UrlObject + ForEach ($SearchByValueItem In $SearchByValue) + { + If (!($PSCmdlet.ParameterSetName -eq 'Default')) { $QueryStrings = @() $BodyParts = @() - # Populate Url placeholders. Assumption is that if an endpoint requires an Id to be passed in the Url that it does not require a filter because its looking for an exact match already. - If ($Url -match '({)(.*?)(})') + # Populate url variables + $UrlOut = Switch ($SearchBy) { - Write-Verbose ('Populating ' + $Matches[0] + ' with ' + $SearchByValueItem) - $UrlOut = $Url.Replace($Matches[0], $SearchByValueItem) - } - Else - { - Switch ($SearchBy) + 'ById' { - 'ById' + If ($JCType.Url.variables) { - $UrlOut = $Url + '/' + $SearchByValueItem + ($JCType.Url.Item).Replace($JCType.Url.variables, $SearchByValueItem) } - 'ByName' + Else { - $UrlOut = $Url - # Add filters for exact match and wildcards - If ($SearchByValueItem -match '\*') - { - If ($SupportRegexFilter) - { - $BodyParts += ('"filter":[{"' + $PropertyIdentifier + '":{"$regex": "(?i)(' + $SearchByValueItem.Replace('*', ')(.*?)(') + ')"}}]').Replace('()', '') - } - Else - { - Write-Error ('The endpoint ' + $UrlOut + ' does not support wildcards in the $SearchByValueItem. Please remove "*" from "' + $SearchByValueItem + '".') - } - } - Else - { - $QueryStrings += 'filter=' + $PropertyIdentifier + ':eq:' + $SearchByValueItem - $BodyParts += '"filter":[{"' + $PropertyIdentifier + '":"' + $SearchByValueItem + '"}]' - } + $JCType.Url.Item } - Default {Write-Error ('Unknown $SearchBy value: ' + $SearchBy)} + } + 'ByName' + { + $JCType.Url.List } } - # Build query string and body - $JoinedQueryStrings = $QueryStrings -join '&' - $JoinedBodyParts = $BodyParts -join ',' - # Build final body and url - If ($JoinedBodyParts) - { - $Body = '{' + $JoinedBodyParts + '}' - } - If ($JoinedQueryStrings) + If ($SearchBy -eq 'ByName') { - $UrlOut = $UrlOut + '?' + $JoinedQueryStrings - } - $UrlObject += [PSCustomObject]@{ - 'Url' = $UrlOut; - 'Body' = $Body; - 'SearchByValueItem' = $SearchByValueItem; + # Add filters for exact match and wildcards + If ($SearchByValueItem -match '\*') + { + If ($JCType.SupportRegexFilter) + { + $BodyParts += ('"filter":[{"' + $PropertyIdentifier + '":{"$regex": "(?i)(' + $SearchByValueItem.Replace('*', ')(.*?)(') + ')"}}]').Replace('()', '') + } + Else + { + Write-Error ('The endpoint ' + $UrlOut + ' does not support wildcards in the $SearchByValueItem. Please remove "*" from "' + $SearchByValueItem + '".') + } + } + Else + { + $QueryStrings += 'filter=' + $PropertyIdentifier + ':eq:' + $SearchByValueItem + '&fields=' + $JCType.ById + $BodyParts += '"filter":[{"' + $PropertyIdentifier + '":"' + $SearchByValueItem + '"}]' + } } } + # Build url info + $QueryString = If ($QueryStrings) {'?' + ($QueryStrings -join '&')} Else {$null}; + $Body = If ($BodyParts) {'{' + ($BodyParts -join ',') + '}'} Else {$null}; + $UrlObject += [PSCustomObject]@{ + 'Type' = $Type; + 'SearchBy' = $SearchBy; + 'SearchByValueItem' = $SearchByValueItem; + 'UrlPath' = $UrlOut; + 'QueryString' = $QueryString; + 'Body' = $Body; + 'UrlFull' = $JCUrlBasePath + $UrlOut + $QueryString; + } } + ######################################################### + # $UrlObject + ######################################################### + # Make each API call ForEach ($UrlItem In $UrlObject) { - $Url = $UrlItem.Url + $UrlFull = $UrlItem.UrlFull $Body = $UrlItem.Body $SearchByValueItem = $UrlItem.SearchByValueItem + $SearchBy = $UrlItem.SearchBy + If ($SearchBy -eq 'ByName') + { + $FieldsReturned = $JCType.ById + } + Else + { + $FieldsReturned = $Fields + } ## Escape Url???? - # $Url = ([uri]::EscapeDataString($Url) + # $UrlFull= ([uri]::EscapeDataString($UrlFull) # Build function parameters $FunctionParameters = [ordered]@{ } - If ($Url) { $FunctionParameters.Add('Url', $Url) } - If ($Method) { $FunctionParameters.Add('Method', $Method) } - If ($Body) { $FunctionParameters.Add('Body', $Body) } - If ($Limit) { $FunctionParameters.Add('Limit', $Limit) } - If ($Skip) { $FunctionParameters.Add('Skip', $Skip) } + If (-not ([System.String]::IsNullOrEmpty($UrlFull))) { $FunctionParameters.Add('Url', $UrlFull) } + If (-not ([System.String]::IsNullOrEmpty($JCType.Method))) { $FunctionParameters.Add('Method', $JCType.Method) } + If (-not ([System.String]::IsNullOrEmpty($Body))) { $FunctionParameters.Add('Body', $Body) } + If (-not ([System.String]::IsNullOrEmpty($Limit))) { $FunctionParameters.Add('Limit', $Limit) } + If (-not ([System.String]::IsNullOrEmpty($Skip))) { $FunctionParameters.Add('Skip', $Skip) } If ($ReturnHashTable) { - $Values = $Fields - $Key = If ($PropertyIdentifier) { $PropertyIdentifier } Else { $ById } - If ($Key) { $FunctionParameters.Add('Key', $Key) } - If ($Values) { $FunctionParameters.Add('Values', $Values) } + $Values = $FieldsReturned + $Key = If ($PropertyIdentifier) { $PropertyIdentifier } Else { $JCType.ById } + If (-not ([System.String]::IsNullOrEmpty($Key))) { $FunctionParameters.Add('Key', $Key) } + If (-not ([System.String]::IsNullOrEmpty($Values))) { $FunctionParameters.Add('Values', $Values) } } Else { - If ($Fields) { $FunctionParameters.Add('Fields', $Fields) } - $FunctionParameters.Add('Paginate', $Paginate) + If (-not ([System.String]::IsNullOrEmpty($FieldsReturned))) { $FunctionParameters.Add('Fields', $FieldsReturned) } + If (-not ([System.String]::IsNullOrEmpty($Paginate))) { $FunctionParameters.Add('Paginate', $Paginate) } If ($ReturnCount -eq $true) { $FunctionParameters.Add('ReturnCount', $ReturnCount) } } # Hacky logic for organization - If ($TypeNameSingular -eq 'organization') + If ($JCType.TypeName.TypeNameSingular -eq 'organization') { $Organization = Invoke-JCApi @FunctionParameters - $FunctionParameters['Url'] = $Url + '/' + $Organization.$ById + $FunctionParameters['Url'] = $UrlFull + '/' + $Organization.($JCType.ById) } # Run command - $Result = Switch ($ReturnHashTable) + $Result = If ($ReturnHashTable -eq $true) + { + Get-JCHash @FunctionParameters + } + Else { - $true { Get-JCHash @FunctionParameters } - Default { Invoke-JCApi @FunctionParameters } + Invoke-JCApi @FunctionParameters } - # Hacky logic to get g_suite and office_365directories - If ($TypeNameSingular -in ('g_suite', 'office_365')) + If ($JCType.TypeName.TypeNameSingular -in ('g_suite', 'office_365')) # Hacky logic to get g_suite and office_365 directories { If ($ReturnCount -eq $true) { - $Directory = $Result.results | Where-Object { $_.Type -eq $TypeNameSingular } + $Directory = $Result.results | Where-Object { $_.Type -eq $JCType.TypeName.TypeNameSingular } $Result.totalCount = ($Directory | Measure-Object).Count $Result.results = $Directory } Else { - $Result = $Result | Where-Object { $_.Type -eq $TypeNameSingular } + $Result = $Result | Where-Object { $_.Type -eq $JCType.TypeName.TypeNameSingular } } } + # Validate results If ($Result -and $Result.PSObject.Properties.name -notcontains 'NoContent') { - If ($SearchBy -and ($Result | Measure-Object).Count -gt 1) + If ($SearchBy -and ($Result | Measure-Object).Count -gt 1 -and $UrlFull -notlike '*SystemInsights*') { - Write-Warning -Message:('Found "' + [string]($Result | Measure-Object).Count + '" "' + $TypeNamePlural + '" with the "' + $SearchBy.Replace('By', '').ToLower() + '" of "' + $SearchByValueItem + '"') + Write-Warning -Message:('Found "' + [string]($Result | Measure-Object).Count + '" "' + $JCType.TypeName.TypeNamePlural + '" with the "' + $SearchBy.Replace('By', '').ToLower() + '" of "' + $SearchByValueItem + '"') } - # If ($PSCmdlet.ParameterSetName -eq 'Default' -and $TypeNameSingular -notin ('g_suite', 'office_365') -and $Url -notlike '*/api/v2/directories*' -and $Url -notlike '*/groups*' -and $Url -notlike '*/api/organizations*' -and $Url -notlike '*/api/search*') - # { - # $Results = $Result | ForEach-Object { Get-JCObject -Type:($TypeNameSingular) -Id:($_.($ById))} - # } - # Else - # { - + $Results += $Result + } + ElseIf ($SearchByValueItem) + { + If ($PsBoundParameters.Table) + { + Write-Warning ('SystemInsights data not found in "' + $PsBoundParameters.Table + '" where "' + $SearchBy.Replace('By', '').ToLower() + '" is "' + $SearchByValueItem + '".') + } + Else + { + Write-Warning ('A "' + $JCType.TypeName.TypeNameSingular + '" called "' + $SearchByValueItem + '" does not exist. Note the search is case sensitive.') + } + } + Else + { + Write-Warning ('The search value is blank or no "' + $JCType.TypeName.TypeNamePlural + '" have been setup in your org. SearchValue:"' + $SearchByValueItem + '"') + } + } + # Re-lookup object by id + If ($Results -and $SearchBy -eq 'ByName' -and $JCType.TypeName.TypeNameSingular -notin ('g_suite', 'office_365')) # Hacky logic to get g_suite and office_365 directories + { + $PsBoundParameters.Remove('Name') | Out-Null + $PsBoundParameters.Remove('SearchBy') | Out-Null + $PsBoundParameters.Remove('SearchByValue') | Out-Null + $PsBoundParameters.Add('Id', $Results.($JCType.ById)) | Out-Null + $Results = Get-JCObject @PsBoundParameters + } + Else + { + If ($Results) + { + $ById = $JCType.ById + $ByName = $JCType.ByName + $TypeName = $JCType.TypeName + $TypeNameSingular = $TypeName.TypeNameSingular + $TypeNamePlural = $TypeName.TypeNamePlural + $Targets = $JCType.Targets + $TargetSingular = $Targets.TargetSingular + $TargetPlural = $Targets.TargetPlural + $Table = $JCType.Table # List values to add to results - $HiddenProperties = @('ById', 'ByName', 'TypeName', 'TypeNameSingular', 'TypeNamePlural', 'Targets', 'TargetSingular', 'TargetPlural') + $HiddenProperties = @('ById', 'ByName', 'TypeName', 'TypeNameSingular', 'TypeNamePlural', 'Targets', 'TargetSingular', 'TargetPlural', 'Table') # Append meta info to each result record Get-Variable -Name:($HiddenProperties) | ForEach-Object { $Variable = $_ - $Result | + $Results | ForEach-Object { - Add-Member -InputObject:($_) -MemberType:('NoteProperty') -Name:($Variable.Name) -Value:($Variable.Value) + If (-not ([System.String]::IsNullOrEmpty($Variable.Value))) + { + Add-Member -InputObject:($_) -MemberType:('NoteProperty') -Name:($Variable.Name) -Value:($Variable.Value); + } } } # Set the meta info to be hidden by default - $Results += Hide-ObjectProperty -Object:($Result) -HiddenProperties:($HiddenProperties) - } - Else - { - If ($SearchByValueItem) - { - Write-Warning ('A "' + $TypeNameSingular + '" called "' + $SearchByValueItem + '" does not exist. Note the search is case sensitive.') - } - Else - { - Write-Warning ('The search value is blank or no "' + $TypeNamePlural + '" have been setup in your org. SearchValue:"' + $SearchByValueItem + '"') - } + $Results = Hide-ObjectProperty -Object:($Results) -HiddenProperties:($HiddenProperties) } - # } } } Else { - Write-Error ('$Type of "' + $Type + '" not found. $Type must be:' + ($JCTypes.TypeName.TypeNameSingular -join ',')) + Write-Error ('$Type of "' + $Type + '" not found. $Type must be:' + ($JCType.TypeName.TypeNameSingular -join ',')) } } Catch diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Hide-ObjectProperty.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Hide-ObjectProperty.ps1 index 33ea1fd28..0e1178a46 100644 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/Hide-ObjectProperty.ps1 +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Hide-ObjectProperty.ps1 @@ -31,7 +31,6 @@ Function Hide-ObjectProperty ) # Set some properties to be hidden in the results $Object | ForEach-Object { - $Record = $_ # Get current object's properties $ObjectAllProperties = $_.PSObject.Properties.Name # Write-Host ('ObjectAllProperties:' + ($ObjectAllProperties -join ', ')) -BackgroundColor Gray -ForegroundColor Black @@ -39,7 +38,7 @@ Function Hide-ObjectProperty If ($_.PSStandardMembers) { $ObjectShowProperties = $_.PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames - $PropertiesToHide = @($ObjectAllProperties | Where-Object {$_ -notin $ObjectShowProperties -or $_ -in $HiddenProperties}) + $PropertiesToHide = @($HiddenProperties + ($ObjectAllProperties | Where-Object {$_ -notin $ObjectShowProperties -or $_ -in $HiddenProperties}) | Select-Object -Unique) # Write-Host ('ObjectShowProperties:' + ($ObjectShowProperties -join ', ')) -BackgroundColor Yellow -ForegroundColor Black } Else @@ -57,13 +56,6 @@ Function Hide-ObjectProperty $PSStandardMembers = [System.Management.Automation.PSMemberInfo[]]@($defaultDisplayPropertySet) # Add the list of standard members Add-Member -InputObject:($_) -MemberType:('MemberSet') -Name:('PSStandardMembers') -Value:($PSStandardMembers) -Force - ForEach ($HiddenProperty In $PropertiesToHide) - { - If($HiddenProperty -in $_.PSObject.Properties.Name) - { - Add-Member -InputObject:($_) -MemberType:('NoteProperty') -Name:($HiddenProperty) -Value:($Record.$HiddenProperty) -Force - } - } } Else { diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Invoke-JCApi.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Invoke-JCApi.ps1 index 79ceecd62..a583bfd24 100755 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/Invoke-JCApi.ps1 +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/Invoke-JCApi.ps1 @@ -165,7 +165,7 @@ Function Invoke-JCApi { Write-Error ('Url is not a valid JumpCloud V1 or V2 endpoint') } - If ($ResultPopulated) + If ($ResultPopulated -eq $true) { $Skip += $ResultCount $Results += $ResultObjects @@ -193,29 +193,18 @@ Function Invoke-JCApi { # List values to add to results $HiddenProperties = @('httpMetaData') - # Append meta info to each result record - Get-Variable -Name:($HiddenProperties) | - ForEach-Object { - $Variable = $_ - If ($Results) - { + # Validate that all fields passed into the function exist in the output + If ($Results) + { + # Append meta info to each result record + Get-Variable -Name:($HiddenProperties) | + ForEach-Object { + $Variable = $_ $Results | ForEach-Object { Add-Member -InputObject:($_) -MemberType:('NoteProperty') -Name:($Variable.Name) -Value:($Variable.Value) } } - Else - { - - $Results += [PSCustomObject]@{ - 'NoContent' = $null; - 'httpMetaData' = $httpMetaData; - } - } - } - # Validate that all fields passed into the function exist in the output - If ($Results) - { # Validate results properties returned $Fields | ForEach-Object { If ($_ -notin ($Results | Get-Member).Name) @@ -224,6 +213,13 @@ Function Invoke-JCApi } } } + Else + { + $Results += [PSCustomObject]@{ + 'NoContent' = $null; + 'httpMetaData' = $httpMetaData; + } + } # Set the meta info to be hidden by default Return Hide-ObjectProperty -Object:($Results) -HiddenProperties:($HiddenProperties) } diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/Invoke-SetJCOrganizations.ps1 b/PowerShell/JumpCloud Module/Private/NestedFunctions/Invoke-SetJCOrganization.ps1 similarity index 100% rename from PowerShell/JumpCloud Module/Private/NestedFunctions/Invoke-SetJCOrganizations.ps1 rename to PowerShell/JumpCloud Module/Private/NestedFunctions/Invoke-SetJCOrganization.ps1 diff --git a/PowerShell/JumpCloud Module/Private/NestedFunctions/JCTypes.json b/PowerShell/JumpCloud Module/Private/NestedFunctions/JCTypes.json index 4901c153f..42382cccb 100755 --- a/PowerShell/JumpCloud Module/Private/NestedFunctions/JCTypes.json +++ b/PowerShell/JumpCloud Module/Private/NestedFunctions/JCTypes.json @@ -1,6 +1,6 @@ [ { - "Category": "JumpCloud", + "Category": "Temp-Removed", "TypeName": { "TypeNameSingular": "active_directory", "TypeNamePlural": "activedirectories" @@ -15,13 +15,20 @@ "TargetPlural": "usergroups" } ], - "Url": "/api/v2/activedirectories", + "Url": { + "List": "/api/v2/activedirectories", + "Item": "/api/v2/activedirectories/{id}", + "Variables": [ + "{id}" + ] + }, "Method": "GET", "ById": "id", "ByName": "domain", "Paginate": true, "SupportRegexFilter": true, - "Limit": 100 + "Limit": 100, + "Skip": 0 }, { "Category": "JumpCloud", @@ -35,13 +42,20 @@ "TargetPlural": "usergroups" } ], - "Url": "/api/applications", + "Url": { + "List": "/api/applications", + "Item": "/api/applications/{id}", + "Variables": [ + "{id}" + ] + }, "Method": "GET", "ById": "_id", "ByName": "displayName", "Paginate": true, "SupportRegexFilter": false, "Limit": 100, + "Skip": 0, "TargetsExcluded": [ { "TargetExcludedSingular": "user", @@ -65,13 +79,20 @@ "TargetPlural": "systemgroups" } ], - "Url": "/api/commands", + "Url": { + "List": "/api/commands", + "Item": "/api/commands/{id}", + "Variables": [ + "{id}" + ] + }, "Method": "GET", "ById": "_id", "ByName": "name", "Paginate": true, "SupportRegexFilter": false, - "Limit": 100 + "Limit": 100, + "Skip": 0 }, { "Category": "JumpCloud", @@ -89,13 +110,18 @@ "TargetPlural": "usergroups" } ], - "Url": "/api/v2/directories", + "Url": { + "List": "/api/v2/directories", + "Item": "/api/v2/directories", + "Variables": [] + }, "Method": "GET", "ById": "id", "ByName": "name", "Paginate": true, "SupportRegexFilter": false, - "Limit": 100 + "Limit": 100, + "Skip": 0 }, { "Category": "JumpCloud", @@ -113,13 +139,20 @@ "TargetPlural": "usergroups" } ], - "Url": "/api/v2/ldapservers", + "Url": { + "List": "/api/v2/ldapservers", + "Item": "/api/v2/ldapservers/{id}", + "Variables": [ + "{id}" + ] + }, "Method": "GET", "ById": "id", "ByName": "name", "Paginate": true, "SupportRegexFilter": true, - "Limit": 100 + "Limit": 100, + "Skip": 0 }, { "Category": "JumpCloud", @@ -137,13 +170,18 @@ "TargetPlural": "usergroups" } ], - "Url": "/api/v2/directories", + "Url": { + "List": "/api/v2/directories", + "Item": "/api/v2/directories", + "Variables": [] + }, "Method": "GET", "ById": "id", "ByName": "name", "Paginate": true, "SupportRegexFilter": false, - "Limit": 100 + "Limit": 100, + "Skip": 0 }, { "Category": "JumpCloud", @@ -161,13 +199,20 @@ "TargetPlural": "systemgroups" } ], - "Url": "/api/v2/policies", + "Url": { + "List": "/api/v2/policies", + "Item": "/api/v2/policies/{id}", + "Variables": [ + "{id}" + ] + }, "Method": "GET", "ById": "id", "ByName": "name", "Paginate": true, "SupportRegexFilter": false, - "Limit": 100 + "Limit": 100, + "Skip": 0 }, { "Category": "JumpCloud", @@ -181,13 +226,20 @@ "TargetPlural": "usergroups" } ], - "Url": "/api/radiusservers", + "Url": { + "List": "/api/radiusservers", + "Item": "/api/radiusservers/{id}", + "Variables": [ + "{id}" + ] + }, "Method": "GET", "ById": "_id", "ByName": "name", "Paginate": true, "SupportRegexFilter": false, "Limit": 100, + "Skip": 0, "TargetsExcluded": [ { "TargetExcludedSingular": "user", @@ -219,13 +271,20 @@ "TargetPlural": "systems" } ], - "Url": "/api/v2/systemgroups", + "Url": { + "List": "/api/v2/systemgroups", + "Item": "/api/v2/systemgroups/{id}", + "Variables": [ + "{id}" + ] + }, "Method": "GET", "ById": "id", "ByName": "name", "Paginate": true, "SupportRegexFilter": true, "Limit": 100, + "Skip": 0, "TargetsExcluded": [ { "TargetExcludedSingular": "user", @@ -257,18 +316,267 @@ "TargetPlural": "systemgroups" } ], - "Url": "/api/systems", + "Url": { + "List": "/api/systems", + "Item": "/api/systems/{id}", + "Variables": [ + "{id}" + ] + }, "Method": "GET", "ById": "_id", "ByName": "displayName", "Paginate": true, "SupportRegexFilter": true, "Limit": 100, + "Skip": 0, "TargetsExcluded": [ { "TargetExcludedSingular": "user_group", "TargetExcludedPlural": "usergroups" } + ], + "SystemInsights": [ + { + "Table": "apps", + "Url": { + "List": "/api/v2/systeminsights/apps", + "Item": "/api/v2/systeminsights/{system_id}/apps", + "Variables": [ + "{system_id}" + ] + }, + "Method": "GET", + "ById": "jc_system_id", + "ByName": "bundle_name", + "Paginate": true, + "SupportRegexFilter": false, + "Limit": 100, + "Skip": 0, + "FilterOperators": [ + "eq" + ] + }, + { + "Table": "browser_plugins", + "Url": { + "List": "/api/v2/systeminsights/browser_plugins", + "Item": "/api/v2/systeminsights/{system_id}/browser_plugins", + "Variables": [ + "{system_id}" + ] + }, + "Method": "GET", + "ById": "jc_system_id", + "ByName": "name", + "Paginate": true, + "SupportRegexFilter": false, + "Limit": 100, + "Skip": 0, + "FilterOperators": [ + "eq" + ] + }, + { + "Table": "chrome_extensions", + "Url": { + "List": "/api/v2/systeminsights/chrome_extensions", + "Item": "/api/v2/systeminsights/{system_id}/chrome_extensions", + "Variables": [ + "{system_id}" + ] + }, + "Method": "GET", + "ById": "jc_system_id", + "ByName": "name", + "Paginate": true, + "SupportRegexFilter": false, + "Limit": 100, + "Skip": 0, + "FilterOperators": [ + "eq" + ] + }, + { + "Table": "disk_encryption", + "Url": { + "List": "/api/v2/systeminsights/disk_encryption", + "Item": "/api/v2/systeminsights/{system_id}/disk_encryption", + "Variables": [ + "{system_id}" + ] + }, + "Method": "GET", + "ById": "jc_system_id", + "ByName": "encryption_status", + "Paginate": true, + "SupportRegexFilter": false, + "Limit": 100, + "Skip": 0, + "FilterOperators": [ + "eq" + ] + }, + { + "Table": "firefox_addons", + "Url": { + "List": "/api/v2/systeminsights/firefox_addons", + "Item": "/api/v2/systeminsights/{system_id}/firefox_addons", + "Variables": [ + "{system_id}" + ] + }, + "Method": "GET", + "ById": "jc_system_id", + "ByName": "name", + "Paginate": true, + "SupportRegexFilter": false, + "Limit": 100, + "Skip": 0, + "FilterOperators": [ + "eq" + ] + }, + { + "Table": "groups", + "Url": { + "List": "/api/v2/systeminsights/groups", + "Item": "/api/v2/systeminsights/{system_id}/groups", + "Variables": [ + "{system_id}" + ] + }, + "Method": "GET", + "ById": "jc_system_id", + "ByName": "groupname", + "Paginate": true, + "SupportRegexFilter": false, + "Limit": 100, + "Skip": 0, + "FilterOperators": [ + "eq" + ] + }, + { + "Table": "interface_addresses", + "Url": { + "List": "/api/v2/systeminsights/interface_addresses", + "Item": "/api/v2/systeminsights/{system_id}/interface_addresses", + "Variables": [ + "{system_id}" + ] + }, + "Method": "GET", + "ById": "jc_system_id", + "ByName": "address", + "Paginate": true, + "SupportRegexFilter": false, + "Limit": 100, + "Skip": 0, + "FilterOperators": [ + "eq" + ] + }, + { + "Table": "mounts", + "Url": { + "List": "/api/v2/systeminsights/mounts", + "Item": "/api/v2/systeminsights/{system_id}/mounts", + "Variables": [ + "{system_id}" + ] + }, + "Method": "GET", + "ById": "jc_system_id", + "ByName": "path", + "Paginate": true, + "SupportRegexFilter": false, + "Limit": 100, + "Skip": 0, + "FilterOperators": [ + "eq" + ] + }, + { + "Table": "os_version", + "Url": { + "List": "/api/v2/systeminsights/os_version", + "Item": "/api/v2/systeminsights/{system_id}/os_version", + "Variables": [ + "{system_id}" + ] + }, + "Method": "GET", + "ById": "jc_system_id", + "ByName": "version", + "Paginate": true, + "SupportRegexFilter": false, + "Limit": 100, + "Skip": 0, + "FilterOperators": [ + "eq" + ] + }, + { + "Table": "safari_extensions", + "Url": { + "List": "/api/v2/systeminsights/safari_extensions", + "Item": "/api/v2/systeminsights/{system_id}/safari_extensions", + "Variables": [ + "{system_id}" + ] + }, + "Method": "GET", + "ById": "jc_system_id", + "ByName": "name", + "Paginate": true, + "SupportRegexFilter": false, + "Limit": 100, + "Skip": 0, + "FilterOperators": [ + "eq" + ] + }, + { + "Table": "system_info", + "Url": { + "List": "/api/v2/systeminsights/system_info", + "Item": "/api/v2/systeminsights/{system_id}/system_info", + "Variables": [ + "{system_id}" + ] + }, + "Method": "GET", + "ById": "jc_system_id", + "ByName": "cpu_subtype", + "Paginate": true, + "SupportRegexFilter": false, + "Limit": 100, + "Skip": 0, + "FilterOperators": [ + "eq" + ] + }, + { + "Table": "users", + "Url": { + "List": "/api/v2/systeminsights/users", + "Item": "/api/v2/systeminsights/{system_id}/users", + "Variables": [ + "{system_id}" + ] + }, + "Method": "GET", + "ById": "jc_system_id", + "ByName": "username", + "Paginate": true, + "SupportRegexFilter": false, + "Limit": 100, + "Skip": 0, + "FilterOperators": [ + "eq" + ] + } ] }, { @@ -307,13 +615,20 @@ "TargetPlural": "users" } ], - "Url": "/api/v2/usergroups", + "Url": { + "List": "/api/v2/usergroups", + "Item": "/api/v2/usergroups/{id}", + "Variables": [ + "{id}" + ] + }, "Method": "GET", "ById": "id", "ByName": "name", "Paginate": true, "SupportRegexFilter": true, "Limit": 100, + "Skip": 0, "TargetsExcluded": [ { "TargetExcludedSingular": "system", @@ -353,13 +668,20 @@ "TargetPlural": "usergroups" } ], - "Url": "/api/systemusers", + "Url": { + "List": "/api/systemusers", + "Item": "/api/systemusers/{id}", + "Variables": [ + "{id}" + ] + }, "Method": "GET", "ById": "_id", "ByName": "username", "Paginate": true, "SupportRegexFilter": true, "Limit": 100, + "Skip": 0, "TargetsExcluded": [ { "TargetExcludedSingular": "active_directory", @@ -386,13 +708,18 @@ "TypeNamePlural": "directories" }, "Targets": null, - "Url": "/api/v2/directories", + "Url": { + "List": "/api/v2/directories", + "Item": "/api/v2/directories", + "Variables": [] + }, "Method": "GET", "ById": "id", "ByName": "name", "Paginate": true, "SupportRegexFilter": false, - "Limit": 100 + "Limit": 100, + "Skip": 0 }, { "Category": "Custom", @@ -401,13 +728,20 @@ "TypeNamePlural": "groups" }, "Targets": null, - "Url": "/api/v2/groups", + "Url": { + "List": "/api/v2/groups", + "Item": "/api/v2/groups/{id}", + "Variables": [ + "{id}" + ] + }, "Method": "GET", "ById": "id", "ByName": "name", "Paginate": true, "SupportRegexFilter": false, - "Limit": 100 + "Limit": 100, + "Skip": 0 }, { "Category": "Custom", @@ -416,13 +750,20 @@ "TypeNamePlural": "organizations" }, "Targets": null, - "Url": "/api/organizations", + "Url": { + "List": "/api/organizations", + "Item": "/api/organizations/{id}", + "Variables": [ + "{id}" + ] + }, "Method": "GET", "ById": "_id", "ByName": "displayName", "Paginate": true, "SupportRegexFilter": false, - "Limit": 100 + "Limit": 100, + "Skip": 0 }, { "Category": "Custom", @@ -452,13 +793,20 @@ "TargetPlural": "usergroups" } ], - "Url": "/api/search/systemusers", + "Url": { + "List": "/api/search/systemusers", + "Item": null, + "Variables": [ + null + ] + }, "Method": "POST", "ById": "_id", "ByName": "username", "Paginate": true, "SupportRegexFilter": true, "Limit": 100, + "Skip": 0, "TargetsExcluded": [ { "TargetExcludedSingular": "active_directory", @@ -490,12 +838,19 @@ "TargetPlural": "systemgroups" } ], - "Url": "/api/search/systems", + "Url": { + "List": "/api/search/systems", + "Item": null, + "Variables": [ + null + ] + }, "Method": "POST", "ById": "_id", "ByName": "displayName", "Paginate": true, "SupportRegexFilter": true, - "Limit": 100 + "Limit": 100, + "Skip": 0 } ] \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Private/ScriptBlocks/ScriptBlock_DefaultDynamicParamProcess.ps1 b/PowerShell/JumpCloud Module/Private/ScriptBlocks/ScriptBlock_DefaultDynamicParamProcess.ps1 index dc9ebedb4..c3ac2c431 100755 --- a/PowerShell/JumpCloud Module/Private/ScriptBlocks/ScriptBlock_DefaultDynamicParamProcess.ps1 +++ b/PowerShell/JumpCloud Module/Private/ScriptBlocks/ScriptBlock_DefaultDynamicParamProcess.ps1 @@ -17,8 +17,18 @@ $ScriptBlock_DefaultDynamicParamProcess = { # For DynamicParam with a default value set that value $DynamicParams.Values | Where-Object { $_.IsSet -and $_.Attributes.ParameterSetName -in ($ScriptPSCmdlet.ParameterSetName, '__AllParameterSets') } | - ForEach-Object { $ScriptPsBoundParameters[$_.Name] = $_.Value } + ForEach-Object { + If (-not ([System.String]::IsNullOrEmpty($_.Value))) + { + $ScriptPsBoundParameters[$_.Name] = $_.Value + } + } # Convert the DynamicParam inputs into new variables for the script to use $ScriptPsBoundParameters.GetEnumerator() | - ForEach-Object {Set-Variable -Name:($_.Key) -Value:($_.Value) -Force} + ForEach-Object { + If (-not ([System.String]::IsNullOrEmpty($_.Value))) + { + Set-Variable -Name:($_.Key) -Value:($_.Value) -Force + } + } } diff --git a/PowerShell/JumpCloud Module/Public/Association/Add-JCAssociation.ps1 b/PowerShell/JumpCloud Module/Public/Association/Add-JCAssociation.ps1 index f2cc93d28..117336a23 100755 --- a/PowerShell/JumpCloud Module/Public/Association/Add-JCAssociation.ps1 +++ b/PowerShell/JumpCloud Module/Public/Association/Add-JCAssociation.ps1 @@ -2,15 +2,20 @@ Function Add-JCAssociation { [CmdletBinding(DefaultParameterSetName = 'ById')] Param( - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1, HelpMessage = 'The type of the object.')][ValidateNotNullOrEmpty()][ValidateSet('command', 'ldap_server', 'policy', 'application', 'radius_server', 'system_group', 'system', 'user_group', 'user', 'g_suite', 'office_365')][Alias('TypeNameSingular')][string]$Type - , [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, Position = 2, HelpMessage = 'Bypass user confirmation and ValidateSet when adding or removing associations.')][ValidateNotNullOrEmpty()][Switch]$Force + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = 'The type of the object.')][ValidateNotNullOrEmpty()][ValidateSet('command', 'ldap_server', 'policy', 'application', 'radius_server', 'system_group', 'system', 'user_group', 'user', 'g_suite', 'office_365')][Alias('TypeNameSingular')][string]$Type + , [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = 'Bypass user prompts and dynamic ValidateSet.')][ValidateNotNullOrEmpty()][Switch]$Force ) DynamicParam { - # Add Action - ($PsBoundParameters).Add('Action', 'add') | Out-Null - # Build dynamic parameters - $RuntimeParameterDictionary = Get-DynamicParamAssociation @PsBoundParameters + $Action = 'add' + $RuntimeParameterDictionary = If ($Type) + { + Get-DynamicParamAssociation -Action:($Action) -Force:($Force) -Type:($Type) + } + Else + { + Get-DynamicParamAssociation -Action:($Action) -Force:($Force) + } Return $RuntimeParameterDictionary } Begin @@ -27,6 +32,8 @@ Function Add-JCAssociation $FunctionParameters = [ordered]@{} # Add input parameters from function in to hash table and filter out unnecessary parameters $PSBoundParameters.GetEnumerator() | Where-Object {$_.Value} | ForEach-Object {$FunctionParameters.Add($_.Key, $_.Value) | Out-Null} + # Add action + ($FunctionParameters).Add('Action', $Action) | Out-Null # Run the command $Results += Invoke-JCAssociation @FunctionParameters } diff --git a/PowerShell/JumpCloud Module/Public/Association/Get-JCAssociation.ps1 b/PowerShell/JumpCloud Module/Public/Association/Get-JCAssociation.ps1 index 528427f73..5f630a91a 100755 --- a/PowerShell/JumpCloud Module/Public/Association/Get-JCAssociation.ps1 +++ b/PowerShell/JumpCloud Module/Public/Association/Get-JCAssociation.ps1 @@ -2,15 +2,20 @@ Function Get-JCAssociation { [CmdletBinding(DefaultParameterSetName = 'ById')] Param( - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1, HelpMessage = 'The type of the object.')][ValidateNotNullOrEmpty()][ValidateSet('command', 'ldap_server', 'policy', 'application', 'radius_server', 'system_group', 'system', 'user_group', 'user', 'g_suite', 'office_365')][Alias('TypeNameSingular')][string]$Type - , [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, Position = 2, HelpMessage = 'Bypass user confirmation and ValidateSet when adding or removing associations.')][ValidateNotNullOrEmpty()][Switch]$Force + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = 'The type of the object.')][ValidateNotNullOrEmpty()][ValidateSet('command', 'ldap_server', 'policy', 'application', 'radius_server', 'system_group', 'system', 'user_group', 'user', 'g_suite', 'office_365')][Alias('TypeNameSingular')][string]$Type + , [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = 'Bypass user prompts and dynamic ValidateSet.')][ValidateNotNullOrEmpty()][Switch]$Force ) DynamicParam { - # Add Action - ($PsBoundParameters).Add('Action', 'get') | Out-Null - # Build dynamic parameters - $RuntimeParameterDictionary = Get-DynamicParamAssociation @PsBoundParameters + $Action = 'get' + $RuntimeParameterDictionary = If ($Type) + { + Get-DynamicParamAssociation -Action:($Action) -Force:($Force) -Type:($Type) + } + Else + { + Get-DynamicParamAssociation -Action:($Action) -Force:($Force) + } Return $RuntimeParameterDictionary } Begin @@ -27,6 +32,8 @@ Function Get-JCAssociation $FunctionParameters = [ordered]@{} # Add input parameters from function in to hash table and filter out unnecessary parameters $PSBoundParameters.GetEnumerator() | Where-Object {$_.Value} | ForEach-Object {$FunctionParameters.Add($_.Key, $_.Value) | Out-Null} + # Add action + ($FunctionParameters).Add('Action', $Action) | Out-Null # Run the command $Results += Invoke-JCAssociation @FunctionParameters } diff --git a/PowerShell/JumpCloud Module/Public/Association/Remove-JCAssociation.ps1 b/PowerShell/JumpCloud Module/Public/Association/Remove-JCAssociation.ps1 index 0d96c7d1f..82a99d452 100755 --- a/PowerShell/JumpCloud Module/Public/Association/Remove-JCAssociation.ps1 +++ b/PowerShell/JumpCloud Module/Public/Association/Remove-JCAssociation.ps1 @@ -2,15 +2,20 @@ Function Remove-JCAssociation { [CmdletBinding(DefaultParameterSetName = 'ById')] Param( - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1, HelpMessage = 'The type of the object.')][ValidateNotNullOrEmpty()][ValidateSet('command', 'ldap_server', 'policy', 'application', 'radius_server', 'system_group', 'system', 'user_group', 'user', 'g_suite', 'office_365')][Alias('TypeNameSingular')][string]$Type - , [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, Position = 2, HelpMessage = 'Bypass user confirmation and ValidateSet when adding or removing associations.')][ValidateNotNullOrEmpty()][Switch]$Force + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = 'The type of the object.')][ValidateNotNullOrEmpty()][ValidateSet('command', 'ldap_server', 'policy', 'application', 'radius_server', 'system_group', 'system', 'user_group', 'user', 'g_suite', 'office_365')][Alias('TypeNameSingular')][string]$Type + , [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = 'Bypass user prompts and dynamic ValidateSet.')][ValidateNotNullOrEmpty()][Switch]$Force ) DynamicParam { - # Add Action - ($PsBoundParameters).Add('Action', 'remove') | Out-Null - # Build dynamic parameters - $RuntimeParameterDictionary = Get-DynamicParamAssociation @PsBoundParameters + $Action = 'remove' + $RuntimeParameterDictionary = If ($Type) + { + Get-DynamicParamAssociation -Action:($Action) -Force:($Force) -Type:($Type) + } + Else + { + Get-DynamicParamAssociation -Action:($Action) -Force:($Force) + } Return $RuntimeParameterDictionary } Begin @@ -27,6 +32,8 @@ Function Remove-JCAssociation $FunctionParameters = [ordered]@{} # Add input parameters from function in to hash table and filter out unnecessary parameters $PSBoundParameters.GetEnumerator() | Where-Object {$_.Value} | ForEach-Object {$FunctionParameters.Add($_.Key, $_.Value) | Out-Null} + # Add action + ($FunctionParameters).Add('Action', $Action) | Out-Null # Run the command $Results += Invoke-JCAssociation @FunctionParameters } diff --git a/PowerShell/JumpCloud Module/Public/Systems/Get-JCSystem.ps1 b/PowerShell/JumpCloud Module/Public/Systems/Get-JCSystem.ps1 index 6ec5ea957..c16e24072 100644 --- a/PowerShell/JumpCloud Module/Public/Systems/Get-JCSystem.ps1 +++ b/PowerShell/JumpCloud Module/Public/Systems/Get-JCSystem.ps1 @@ -12,6 +12,11 @@ Function Get-JCSystem () [Alias('_id', 'id')] [String]$SystemID, + [Parameter( + ValueFromPipelineByPropertyName, + ParameterSetName = 'ByID', HelpMessage = 'A switch parameter to reveal the SystemFDEKey')] + [switch]$SystemFDEKey, + [Parameter( ValueFromPipelineByPropertyName, @@ -121,7 +126,7 @@ Function Get-JCSystem () [Parameter( ValueFromPipelineByPropertyName, ParameterSetName = 'SearchFilter')] - [ValidateSet('created', 'active', 'agentVersion', 'allowMultiFactorAuthentication', 'allowPublicKeyAuthentication', 'allowSshPasswordAuthentication', 'allowSshRootLogin', 'arch', 'created', 'displayName', 'hostname', 'lastContact', 'modifySSHDConfig', 'organization', 'os', 'remoteIP', 'serialNumber', 'sshdParams', 'systemTimezone', 'templateName', 'version')] + [ValidateSet('created', 'active', 'agentVersion', 'allowMultiFactorAuthentication', 'allowPublicKeyAuthentication', 'allowSshPasswordAuthentication', 'allowSshRootLogin', 'arch', 'created', 'displayName', 'hostname', 'lastContact', 'modifySSHDConfig', 'organization', 'os', 'remoteIP', 'serialNumber', 'sshdParams', 'systemTimezone', 'templateName', 'version', 'fde', 'systemInsights')] [String[]]$returnProperties ) @@ -184,7 +189,7 @@ Function Get-JCSystem () { Write-Verbose 'Verifying JCAPI Key' - if ($JCAPIKEY.length -ne 40) {Connect-JCOnline} + if ($JCAPIKEY.length -ne 40) { Connect-JCOnline } Write-Verbose 'Populating API headers' $hdrs = @{ @@ -215,7 +220,7 @@ Function Get-JCSystem () Write-Verbose "Setting limit to $limit" [int]$skip = '0' - Write-Verbose "Setting limit to $limit" + Write-Verbose "Setting skip to $skip" [int]$Counter = 0 @@ -290,7 +295,7 @@ Function Get-JCSystem () switch ($param.value) { before { $DateQuery = '$lt' } - after { $DateQuery = '$gt'} + after { $DateQuery = '$gt' } } continue @@ -310,17 +315,17 @@ Function Get-JCSystem () if (($param.Value -match '.+?\*$') -and ($param.Value -match '^\*.+?')) { # Front and back wildcard - (($Search.filter).GetEnumerator()).add($param.Key, @{'$regex' = "$Value"}) + (($Search.filter).GetEnumerator()).add($param.Key, @{'$regex' = "$Value" }) } elseif ($param.Value -match '.+?\*$') { # Back wildcard - (($Search.filter).GetEnumerator()).add($param.Key, @{'$regex' = "^$Value"}) + (($Search.filter).GetEnumerator()).add($param.Key, @{'$regex' = "^$Value" }) } elseif ($param.Value -match '^\*.+?') { # Front wild card - (($Search.filter).GetEnumerator()).add($param.Key, @{'$regex' = "$Value`$"}) + (($Search.filter).GetEnumerator()).add($param.Key, @{'$regex' = "$Value`$" }) } else { @@ -332,7 +337,7 @@ Function Get-JCSystem () if ($filterDateProperty) { - (($Search.filter).GetEnumerator()).add($DateProperty, @{$DateQuery = $Timestamp}) + (($Search.filter).GetEnumerator()).add($DateProperty, @{$DateQuery = $Timestamp }) } @@ -356,10 +361,34 @@ Function Get-JCSystem () ByID { - $URL = "$JCUrlBasePath/api/Systems/$SystemID" - Write-Verbose $URL - $results = Invoke-RestMethod -Method GET -Uri $URL -Headers $hdrs -UserAgent:(Get-JCUserAgent) - $null = $resultsArrayList.add($Results) + + if ($SystemFDEKey) + { + + $URL = "$JCUrlBasePath/api/v2/systems/$SystemID/fdekey" + Write-Verbose $URL + + $results = Invoke-RestMethod -Method GET -Uri $URL -Headers $hdrs -UserAgent:(Get-JCUserAgent) + + $FormattedObject = [PSCustomObject]@{ + '_id' = $SystemID; + 'key' = $results.key; + } + + $null = $resultsArrayList.add($FormattedObject) + + } + + else + { + $URL = "$JCUrlBasePath/api/Systems/$SystemID" + Write-Verbose $URL + + $results = Invoke-RestMethod -Method GET -Uri $URL -Headers $hdrs -UserAgent:(Get-JCUserAgent) + $null = $resultsArrayList.add($Results) + } + + } } # End switch diff --git a/PowerShell/JumpCloud Module/Public/Systems/Get-JCSystemInsights.ps1 b/PowerShell/JumpCloud Module/Public/Systems/Get-JCSystemInsights.ps1 new file mode 100644 index 000000000..879d1ab71 --- /dev/null +++ b/PowerShell/JumpCloud Module/Public/Systems/Get-JCSystemInsights.ps1 @@ -0,0 +1,42 @@ +Function Get-JCSystemInsights +{ + [CmdletBinding()] + Param() + DynamicParam + { + $Type = 'system' + $JCTypes = Get-JCType | Where-Object { $_.TypeName.TypeNameSingular -eq $Type }; + $RuntimeParameterDictionary = New-DynamicParameter -Name:('Table') -Type:([System.String]) -Mandatory -ValueFromPipelineByPropertyName -ValidateNotNullOrEmpty -ParameterSets:('Default', 'ById', 'ByName', 'ByValue') -HelpMessage:('The SystemInsights table to query against.') -ValidateSet:($JCTypes.SystemInsights.Table); + Get-JCCommonParameters -Type:($Type) -RuntimeParameterDictionary:($RuntimeParameterDictionary) | Out-Null; + Return $RuntimeParameterDictionary + } + Begin + { + # Debug message for parameter call + Invoke-Command -ScriptBlock:($ScriptBlock_DefaultDebugMessageBegin) -ArgumentList:($MyInvocation, $PsBoundParameters, $PSCmdlet) -NoNewScope + $Results = @() + } + Process + { + # For DynamicParam with a default value set that value and then convert the DynamicParam inputs into new variables for the script to use + Invoke-Command -ScriptBlock:($ScriptBlock_DefaultDynamicParamProcess) -ArgumentList:($PsBoundParameters, $PSCmdlet, $RuntimeParameterDictionary) -NoNewScope + If ($JCSettings.SETTINGS.betaFeatures.systemInsights) + { + # Create hash table to store variables + $FunctionParameters = [ordered]@{} + # Add input parameters from function in to hash table and filter out unnecessary parameters + $PSBoundParameters.GetEnumerator() | Where-Object {$_.Value} | ForEach-Object {$FunctionParameters.Add($_.Key, $_.Value) | Out-Null} + $FunctionParameters.Add('Type', $JCTypes.TypeName.TypeNameSingular) | Out-Null + # Run the command + $Results += Get-JCObject @FunctionParameters + } + Else + { + Write-Error ('SystemInsights is not enabled for your org. Please email JumpCloud at "accounts@jumpcloud.com" to enable the SystemInsights feature.') + } + } + End + { + Return $Results + } +} diff --git a/PowerShell/JumpCloud Module/Tests/InvokePester.ps1 b/PowerShell/JumpCloud Module/Tests/InvokePester.ps1 index ea84a930b..439a4080a 100755 --- a/PowerShell/JumpCloud Module/Tests/InvokePester.ps1 +++ b/PowerShell/JumpCloud Module/Tests/InvokePester.ps1 @@ -1,4 +1,16 @@ -#Requires -Modules Pester, JumpCloud +Param( + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)][ValidateNotNullOrEmpty()][System.String]$TestOrgAPIKey, + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)][ValidateNotNullOrEmpty()][System.String]$MultiTenantAPIKey, + [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, Position = 2)][System.String[]]$ExcludeTagList, + [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, Position = 3)][System.String[]]$IncludeTagList +) +$ModuleManifestName = 'JumpCloud.psd1' +$ModuleManifestPath = "$PSScriptRoot/../$ModuleManifestName" +# Install NuGet +If (!(Get-PackageProvider -Name:('NuGet') -ErrorAction:('SilentlyContinue'))) +{ + Install-PackageProvider NuGet -ForceBootstrap -Force | Out-Null +} # Load config and helper files . ($PSScriptRoot + '/HelperFunctions.ps1') . ($PSScriptRoot + '/TestEnvironmentVariables.ps1') @@ -24,8 +36,6 @@ $Tags = ForEach ($PesterTest In $PesterTests) } } # Filters on tags -$ExcludeTagList = ('') -$IncludeTagList = ('') $IncludeTags = If ($IncludeTagList) { $IncludeTagList @@ -37,11 +47,21 @@ Else # Run Pester tests $PesterResultsFileXml = $PSScriptRoot + '/Pester.Tests.Results.xml' $PesterResultsFileCsv = $PSScriptRoot + '/Pester.Tests.Results.csv' -$PesterResults = Invoke-Pester -Script:(@{ Path = $PSScriptRoot; Parameters = $PesterParams; }) -PassThru -Tag:($IncludeTags) -ExcludeTag:($ExcludeTagList) -OutputFormat:('NUnitXml') -OutputFile:($PesterResultsFileXml) +$PesterResults = Invoke-Pester -Script:(@{ Path = $PSScriptRoot; Parameters = $PesterParams; }) -PassThru -Tag:($IncludeTags) -ExcludeTag:($ExcludeTagList) # -OutputFormat:('NUnitXml') -OutputFile:($PesterResultsFileXml) ## ToDo: Have pester tests export to file # $PesterResults.TestResult | Where-Object {$_.Passed -eq $false} | Export-Csv $PesterResultsFileCsv +$FailedTests = $PesterResults.TestResult | Where-Object {$_.Passed -eq $false} +If ($FailedTests) +{ + Write-Host ('') + Write-Host ('##############################################################################################################') + Write-Host ('##############################Error Description###############################################################') + Write-Host ('##############################################################################################################') + Write-Host ('') + $FailedTests | ForEach-Object {$_.Name + '; ' + $_.FailureMessage + '; '} + Write-Error -Message:('Tests Failed: ' + [string]($FailedTests | Measure-Object).Count) +} - -## Notes for future reporting dashboard for pester +### Notes for future reporting dashboard for pester # Install-PackageProvider -Name:('NuGet') # Install-Package -Name:('extent') # Install-Package extent diff --git a/PowerShell/JumpCloud Module/Tests/ModuleValidation/FunctionFiles.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/ModuleValidation/FunctionFiles.Tests.ps1 new file mode 100755 index 000000000..bac9a421a --- /dev/null +++ b/PowerShell/JumpCloud Module/Tests/ModuleValidation/FunctionFiles.Tests.ps1 @@ -0,0 +1,42 @@ +Describe -Tag:('ModuleValidation') 'Function Format Tests' { + $ModuleRoot = (Get-Item -Path:($PSScriptRoot)).Parent.Parent.FullName + $FunctionList = Get-FunctionReport -Folder:(($ModuleRoot + '/Public'), ($ModuleRoot + '/Private')) | Where-Object {$_.FileName -notlike 'ScriptBlock_*'} + $FunctionList | ForEach-Object { + Context ('Test that the file name matches the function name') { + It ('When FileBaseName "' + $_.FileBaseName + '" equal Function "' + $_.Function + '" for file "' + $_.FileName + '"') { + $_.Function | Should -BeExactly $_.FileBaseName + } + It ('When FileBaseName "' + $_.FileBaseName + '" equal MatchValue "' + $_.MatchValue + '" for file "' + $_.FileName + '"') { + $_.MatchValue | Should -BeExactly $_.FileBaseName + } + } + Context ('Test for missing information') { + It ('When FileName "' + $_.FileName + '" does not contain any functions') { + $_.Function | Should -Not -BeNullOrEmpty + } + } + Context ('Test for multiple functions per file') { + It ('When FileName "' + $_.FileName + '" has exactly 1 function') { + ($_.Function | Measure-Object).Count | Should -BeExactly 1 + ($_.MatchValue | Measure-Object).Count | Should -BeExactly 1 + } + } + } + Context ('Test for duplicate functions') { + ($FunctionList.FileBaseName | Group-Object) | ForEach-Object { + It ('When multiple files with the same name exist for "' + $_.Name + '"') { + $_.Count | Should -Be 1 + } + } + ($FunctionList.Function | Group-Object) | ForEach-Object { + It ('When multiple functions with the same name exist for "' + $_.Name + '"') { + $_.Count | Should -Be 1 + } + } + ($FunctionList.MatchValue | Group-Object) | ForEach-Object { + It ('When multiple MatchValues of functions with the same name exist for "' + $_.Name + '"') { + $_.Count | Should -Be 1 + } + } + } +} \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Tests/ModuleValidation/HelpFiles.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/ModuleValidation/HelpFiles.Tests.ps1 new file mode 100755 index 000000000..a3b61e5a9 --- /dev/null +++ b/PowerShell/JumpCloud Module/Tests/ModuleValidation/HelpFiles.Tests.ps1 @@ -0,0 +1,20 @@ +Describe -Tag:('ModuleValidation') 'Help File Tests' { + $ModuleRoot = (Get-Item -Path:($PSScriptRoot)).Parent.Parent + $ModuleRootFullName = $ModuleRoot.FullName + $Regex_FillInThe = '(\{\{)(.*?)(\}\})' + $Regex_FillInThePester = [regex]('{{.*?}}') + Context ('Validating help file fields have been populated') { + Get-ChildItem -Path:($ModuleRootFullName + '/Docs/*.md') -Recurse | Select-String -Pattern:($Regex_FillInThe) | ForEach-Object { + It ('The file "' + $_.Path + '" needs to be populated on line number "' + $_.LineNumber + '" where "' + $_.Line + '" exists.') { + $_.Path | Should -Not -FileContentMatch ($Regex_FillInThePester) + } + } + } + Context ('Validating that the ModuleBanner and ModuleChangelog fields have been populated') { + Get-ChildItem -Path:($ModuleRoot.Parent.FullName + '/*.md') | Select-String -Pattern:($Regex_FillInThe) | ForEach-Object { + It ('The file "' + $_.Path + '" needs to be populated on line number "' + $_.LineNumber + '" where "' + $_.Line + '" exists.') { + $_.Path | Should -Not -FileContentMatch ($Regex_FillInThePester) + } + } + } +} \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Tests/ModuleValidation/PesterFiles.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/ModuleValidation/PesterFiles.Tests.ps1 new file mode 100755 index 000000000..42b354bc5 --- /dev/null +++ b/PowerShell/JumpCloud Module/Tests/ModuleValidation/PesterFiles.Tests.ps1 @@ -0,0 +1,16 @@ +Describe -Tag:('ModuleValidation') 'Pester Files Tests' { + $ModuleRoot = (Get-Item -Path:($PSScriptRoot)).Parent.Parent.FullName + $FolderTests = ($ModuleRoot + '/Tests') + $FolderPublic = ($ModuleRoot + '/Public') + Context 'Pester Test Files Validation' { + Get-ChildItem -Path:($FolderPublic + '/*.ps1') -Recurse -File | ForEach-Object { + $PesterTestFilePath = ($_.FullName).Replace($ModuleRoot, $FolderTests).Replace($_.Extension, '.Tests' + $_.Extension) + It ('Validating Pester test file exists for "' + $PesterTestFilePath + '"') { + Test-Path -Path:($PesterTestFilePath) | Should -Be $true + } + It ('Validating Pester test file has been populated for "' + $PesterTestFilePath + '"') { + $PesterTestFilePath | Should -FileContentMatch '.*?' + } + } + } +} \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Tests/ModuleValidation/moduleValidation.tests.ps1 b/PowerShell/JumpCloud Module/Tests/ModuleValidation/moduleValidation.tests.ps1 index 3a1a40af6..a8cd76fb3 100755 --- a/PowerShell/JumpCloud Module/Tests/ModuleValidation/moduleValidation.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/ModuleValidation/moduleValidation.tests.ps1 @@ -1,5 +1,5 @@ -Describe -Tag:('moduleValidation') 'Module Manifest Tests' { - It 'Passes Test-ModuleManifest' { +Describe -Tag:('ModuleValidation') 'Module Manifest Tests' { + It ('Passes Test-ModuleManifest') { Test-ModuleManifest -Path $ModuleManifestPath | Should Not BeNullOrEmpty $? | Should Be $true } diff --git a/PowerShell/JumpCloud Module/Tests/Pester.Tests.Results.xml b/PowerShell/JumpCloud Module/Tests/Pester.Tests.Results.xml new file mode 100644 index 000000000..e5b366196 --- /dev/null +++ b/PowerShell/JumpCloud Module/Tests/Pester.Tests.Results.xml @@ -0,0 +1,2156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Tests/Private/Association/Copy-JCAssociation.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/Association/Copy-JCAssociation.Tests.ps1 new file mode 100755 index 000000000..e69de29bb diff --git a/PowerShell/JumpCloud Module/Tests/Private/Association/Format-JCAssociation.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/Association/Format-JCAssociation.Tests.ps1 new file mode 100755 index 000000000..e69de29bb diff --git a/PowerShell/JumpCloud Module/Tests/Private/Association/Get-DynamicParamAssociation.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/Association/Get-DynamicParamAssociation.Tests.ps1 new file mode 100755 index 000000000..e69de29bb diff --git a/PowerShell/JumpCloud Module/Tests/Private/Association/Invoke-JCAssociation.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/Association/Invoke-JCAssociation.Tests.ps1 new file mode 100755 index 000000000..e69de29bb diff --git a/PowerShell/JumpCloud Module/Tests/Private/DynamicParameters/Get-JCCommonParameters.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/DynamicParameters/Get-JCCommonParameters.Tests.ps1 new file mode 100644 index 000000000..e69de29bb diff --git a/PowerShell/JumpCloud Module/Tests/Private/HashFunctions/Get-Hash_employeeIdentifier_username.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/HashFunctions/Get-Hash_employeeIdentifier_username.Tests.ps1 new file mode 100644 index 000000000..e69de29bb diff --git a/PowerShell/JumpCloud Module/Tests/Private/NestedFunctions/Get-FunctionReport.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/NestedFunctions/Get-FunctionReport.Tests.ps1 new file mode 100755 index 000000000..e69de29bb diff --git a/PowerShell/JumpCloud Module/Tests/Private/NestedFunctions/Get-JCType.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/NestedFunctions/Get-JCType.Tests.ps1 new file mode 100755 index 000000000..e69de29bb diff --git a/PowerShell/JumpCloud Module/Tests/Private/NestedFunctions/Get-JCUserAgent.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/NestedFunctions/Get-JCUserAgent.Tests.ps1 new file mode 100755 index 000000000..e69de29bb diff --git a/PowerShell/JumpCloud Module/Tests/Private/NestedFunctions/Hide-ObjectProperty.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/NestedFunctions/Hide-ObjectProperty.Tests.ps1 new file mode 100755 index 000000000..e69de29bb diff --git a/PowerShell/JumpCloud Module/Tests/Private/NestedFunctions/Invoke-SetJCOrganization.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/NestedFunctions/Invoke-SetJCOrganization.Tests.ps1 new file mode 100644 index 000000000..e69de29bb diff --git a/PowerShell/JumpCloud Module/Tests/Private/ScriptBlocks/ScriptBlock_DefaultDebugMessageBegin.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/ScriptBlocks/ScriptBlock_DefaultDebugMessageBegin.Tests.ps1 new file mode 100755 index 000000000..e69de29bb diff --git a/PowerShell/JumpCloud Module/Tests/Private/ScriptBlocks/ScriptBlock_DefaultDynamicParamProcess.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/ScriptBlocks/ScriptBlock_DefaultDynamicParamProcess.Tests.ps1 new file mode 100755 index 000000000..e69de29bb diff --git a/PowerShell/JumpCloud Module/Tests/Private/ScriptBlocks/ScriptBlock_Example.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/ScriptBlocks/ScriptBlock_Example.Tests.ps1 new file mode 100755 index 000000000..e69de29bb diff --git a/PowerShell/JumpCloud Module/Tests/Private/ScriptBlocks/ScriptBlock_TryCatchError.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Private/ScriptBlocks/ScriptBlock_TryCatchError.Tests.ps1 new file mode 100755 index 000000000..e69de29bb diff --git a/PowerShell/JumpCloud Module/Tests/Public/Association/Add-JCAssociation.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Association/Add-JCAssociation.Tests.ps1 new file mode 100755 index 000000000..5cd6ce142 --- /dev/null +++ b/PowerShell/JumpCloud Module/Tests/Public/Association/Add-JCAssociation.Tests.ps1 @@ -0,0 +1 @@ +# See Get-JCAssociation.Tests.ps1 \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Tests/Public/Association/Remove-JCAssociation.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Association/Remove-JCAssociation.Tests.ps1 new file mode 100755 index 000000000..5cd6ce142 --- /dev/null +++ b/PowerShell/JumpCloud Module/Tests/Public/Association/Remove-JCAssociation.Tests.ps1 @@ -0,0 +1 @@ +# See Get-JCAssociation.Tests.ps1 \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandResults/Get-JCCommandResult.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandResults/Get-JCCommandResult.tests.ps1 index ca6b0cc5f..3278d617e 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandResults/Get-JCCommandResult.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandResults/Get-JCCommandResult.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCCommandResult') 'Get-JCCommandResults 1.0' { - + Connect-JCOnlineTest It "Gets all JumpCloud command results" { $CommandResults = Get-JCCommandResult @@ -46,20 +44,6 @@ Describe -Tag:('JCCommandResult') 'Get-JCCommandResults 1.0' { $SingleCommandResult._id | Should -Not -BeNullOrEmpty } - It "Gets all JumpCloud commandresults using -ByID passed through the pipeline" { - - $CommandResults = Get-JCCommandResult | Get-JCCommandResult -ByID - $CommandResults._id.count | Should -BeGreaterThan 1 - - } - - It "Gets all JumpCloud commandresults passed through the pipeline with out declaring -ByID" { - - $CommandResults = Get-JCCommandResult | Get-JCCommandResult - $CommandResults._id.count | Should -BeGreaterThan 1 - - } - } Describe -Tag:('JCCommandResult') "Get-JCCommandResult 1.4.1" { diff --git a/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandResults/Remove-JCCommandResult.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandResults/Remove-JCCommandResult.tests.ps1 index 8885a415b..c25813faf 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandResults/Remove-JCCommandResult.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandResults/Remove-JCCommandResult.tests.ps1 @@ -1,6 +1,5 @@ -Connect-JCOnlineTest Describe -Tag:('JCCommandResult') 'Remove-JCCommandResult 1.0' { - + Connect-JCOnlineTest <# It "Ensures the warning message is displayed by default, Deletes a single JumpCloud command result declaring -CommandResultIT" { $SingleCommandResult = Get-JCCommandResult | Select-Object -Last 1 diff --git a/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandTargets/Add-JCCommandTarget.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandTargets/Add-JCCommandTarget.tests.ps1 index d3418efbc..56ef1f658 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandTargets/Add-JCCommandTarget.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandTargets/Add-JCCommandTarget.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCCommandTarget') 'Add-JCCommandTarget 1.3' { - + Connect-JCOnlineTest It "Adds a single system to a JupmCloud command" { $TargetRemove = Remove-JCCommandTarget -CommandID $PesterParams.CommandID -SystemID $PesterParams.SystemID diff --git a/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandTargets/Get-JCCommandTarget.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandTargets/Get-JCCommandTarget.tests.ps1 index 1398ee6e2..9c859b9a4 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandTargets/Get-JCCommandTarget.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandTargets/Get-JCCommandTarget.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCCommandTarget') 'Get-JCCommandTarget 1.3' { - + Connect-JCOnlineTest It "Returns a JumpCloud commands system targets" { $SystemTarget = Get-JCCommandTarget -CommandID $PesterParams.CommandID diff --git a/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandTargets/Remove-JCCommandTarget.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandTargets/Remove-JCCommandTarget.tests.ps1 index d1ae5cf5d..4c4fe5143 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandTargets/Remove-JCCommandTarget.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Commands/CommandTargets/Remove-JCCommandTarget.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCCommandTarget') 'Add-JCCommandTarget 1.3' { - + Connect-JCOnlineTest It "Removes a single system to a JupmCloud command" { diff --git a/PowerShell/JumpCloud Module/Tests/Public/Commands/Get-JCCommand.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Commands/Get-JCCommand.tests.ps1 index 59d6ee157..cf2d732bc 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Commands/Get-JCCommand.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Commands/Get-JCCommand.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCCommand') 'Get-JCCommand 1.0' { - + Connect-JCOnlineTest It "Gets all JumpCloud commands" { $AllCommands = Get-JCCommand $AllCommands._id.Count | Should -BeGreaterThan 1 diff --git a/PowerShell/JumpCloud Module/Tests/Public/Commands/Import-JCCommand.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Commands/Import-JCCommand.tests.ps1 index 5556b0cdb..9db4a5ae1 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Commands/Import-JCCommand.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Commands/Import-JCCommand.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCCommand') 'Import-JCCommand 1.1' { - + Connect-JCOnlineTest It "Imports a JumpCloud command from a long URL" { $Command = Import-JCCommand -URL 'https://github.com/TheJumpCloud/support/blob/master/PowerShell/JumpCloud%20Commands%20Gallery/Mac%20Commands/Mac%20-%20Get%20Logged%20In%20Users.md' diff --git a/PowerShell/JumpCloud Module/Tests/Public/Commands/Invoke-JCCommand.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Commands/Invoke-JCCommand.tests.ps1 index ee8cb62c9..fed98a602 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Commands/Invoke-JCCommand.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Commands/Invoke-JCCommand.tests.ps1 @@ -1,6 +1,5 @@ -Connect-JCOnlineTest Describe -Tag:('JCCommand') 'Invoke-JCCommand 1.0' { - + Connect-JCOnlineTest It "Invokes a single JumpCloud command declaring the -trigger" { $SingleTrigger = Get-JCCommand | Where-Object trigger -NotLike '' | Select-Object -Last 1 | Select-Object trigger $SingleResult = Invoke-JCCommand -trigger $SingleTrigger.trigger diff --git a/PowerShell/JumpCloud Module/Tests/Public/Commands/Invoke-JCDeployment.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Commands/Invoke-JCDeployment.tests.ps1 index 633c7f883..488b8ca96 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Commands/Invoke-JCDeployment.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Commands/Invoke-JCDeployment.tests.ps1 @@ -1,6 +1,5 @@ -Connect-JCOnlineTest Describe -Tag:('JCDeployment') "Invoke-JCDeployment 1.7.0" { - + Connect-JCOnlineTest It "Invokes a JumpCloud command deployment with 2 systems" { $Invoke2 = Invoke-JCDeployment -CommandID $PesterParams.DeployCommandID -CSVFilePath $JCDeployment_2_CSV diff --git a/PowerShell/JumpCloud Module/Tests/Public/Commands/New-JCCommand.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Commands/New-JCCommand.tests.ps1 index 1a6b251c5..79d01f69c 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Commands/New-JCCommand.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Commands/New-JCCommand.tests.ps1 @@ -1,6 +1,5 @@ -Connect-JCOnlineTest Describe -Tag:('JCCommand') 'New-JCCommand 1.2' { - + Connect-JCOnlineTest It "Creates a new Windows command" { $NewCommand = New-JCCommand -commandType windows -name windows_test -command 'dir' diff --git a/PowerShell/JumpCloud Module/Tests/Public/Commands/New-JCDeploymentTemplate.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Commands/New-JCDeploymentTemplate.tests.ps1 index e69de29bb..7e2a145f0 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Commands/New-JCDeploymentTemplate.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Commands/New-JCDeploymentTemplate.tests.ps1 @@ -0,0 +1 @@ +# Ticket created to populate tests: SA-469 \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Tests/Public/Commands/Remove-JCCommand.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Commands/Remove-JCCommand.tests.ps1 index 402eebfcf..017ecd911 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Commands/Remove-JCCommand.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Commands/Remove-JCCommand.tests.ps1 @@ -1,6 +1,5 @@ -Connect-JCOnlineTest Describe -Tag:('JCCommand') 'Remove-JCCommand 1.2' { - + Connect-JCOnlineTest It "Creates a new Windows command" { $NewCommand = New-JCCommand -commandType windows -name windows_test -command 'dir' diff --git a/PowerShell/JumpCloud Module/Tests/Public/Commands/Set-JCCommand.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Commands/Set-JCCommand.tests.ps1 index 1d35b1d52..1fc2d7956 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Commands/Set-JCCommand.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Commands/Set-JCCommand.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCCommand') "Set-JCCommand 1.7" { - + Connect-JCOnlineTest It "Updates the command" { $CmdUpdate = Set-JCCommand -CommandID $PesterParams.SetCommandID -command "Updated command" $CmdUpdate.command | Should -be "Updated command" diff --git a/PowerShell/JumpCloud Module/Tests/Public/Groups/Get-JCGroup.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Groups/Get-JCGroup.tests.ps1 index 4aae7b377..1aa4a5e92 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Groups/Get-JCGroup.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Groups/Get-JCGroup.tests.ps1 @@ -1,7 +1,5 @@ -#Connect-JCOnlineTest - Describe -Tag:('JCGroup') 'Get-JCGroup 1.0' { - + Connect-JCOnlineTest It 'Gets all groups: System and User' { $Groups = Get-JCGroup diff --git a/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/Add-JCSystemGroupMember.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/Add-JCSystemGroupMember.tests.ps1 index ce500188d..62999109a 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/Add-JCSystemGroupMember.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/Add-JCSystemGroupMember.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCSystemGroupMember') 'Add-JCSystemGroupMember 1.0' { - + Connect-JCOnlineTest It "Adds a JumpCloud system to a JumpCloud system group by System Groupname and SystemID" { $SingleSystemGroupRemove = Remove-JCSystemGroupMember -SystemID $PesterParams.SystemID -GroupName $PesterParams.SystemGroupName diff --git a/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/Get-JCSystemGroupMember.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/Get-JCSystemGroupMember.tests.ps1 index 1d3682266..816137ac9 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/Get-JCSystemGroupMember.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/Get-JCSystemGroupMember.tests.ps1 @@ -1,6 +1,5 @@ -Connect-JCOnlineTest Describe -Tag:('JCSystemGroupMember') 'Get-JCSystemGroupMember 1.0' { - + Connect-JCOnlineTest It 'Gets a System Groups membership by Groupname' { $MultiSystemGroupAdd = Get-JCSystem | Select-Object -Last 2 | Add-JCSystemGroupMember -GroupName $PesterParams.SystemGroupName diff --git a/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/New-JCSystemGroup.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/New-JCSystemGroup.tests.ps1 index 3551ea581..249ff0a8b 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/New-JCSystemGroup.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/New-JCSystemGroup.tests.ps1 @@ -1,6 +1,5 @@ -Connect-JCOnlineTest Describe -Tag:('JCSystemGroup') 'New-JCSystemGroup 1.0' { - + Connect-JCOnlineTest It "Creates a new system group" { $NewG = New-JCSystemGroup -GroupName $(New-RandomString 8) $NewG.Result | Should -Be 'Created' diff --git a/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/Remove-JCSystemGroup.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/Remove-JCSystemGroup.tests.ps1 index 339731498..9acd67094 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/Remove-JCSystemGroup.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/Remove-JCSystemGroup.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCSystemGroup') 'Remove-JCSystemGroup 1.0' { - + Connect-JCOnlineTest It "Removes a system group" { $NewG = New-JCSystemGroup -GroupName $(New-RandomString 8) $DeletedG = Remove-JCSystemGroup -GroupName $NewG.name -force diff --git a/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/Remove-JCSystemGroupMember.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/Remove-JCSystemGroupMember.tests.ps1 index 00ad21718..74c0569e0 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/Remove-JCSystemGroupMember.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Groups/SystemGroups/Remove-JCSystemGroupMember.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest Describe -Tag:('JCSystemGroupMember') 'Remove-JCSystemGroupMember 1.0' { - - + Connect-JCOnlineTest It "Removes a JumpCloud system from a JumpCloud system group by System Groupname and SystemID" { $SingleSystemGroupAdd = Add-JCSystemGroupMember -SystemID $PesterParams.SystemID -GroupName $PesterParams.SystemGroupName diff --git a/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Add-JCUserGroupMember.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Add-JCUserGroupMember.tests.ps1 index 04079ad77..cb5dcdcf3 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Add-JCUserGroupMember.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Add-JCUserGroupMember.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCUserGroupMember') 'Add-JCUserGroupMember 1.0' { - + Connect-JCOnlineTest It "Adds a JumpCloud user to a JumpCloud user group by User GroupName and Username" { $SingleUserGroupRemove = Remove-JCUserGroupMember -GroupName $PesterParams.UserGroupName -username $PesterParams.Username diff --git a/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Get-JCUserGroupMember.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Get-JCUserGroupMember.tests.ps1 index 4853d7054..f07aaa002 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Get-JCUserGroupMember.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Get-JCUserGroupMember.tests.ps1 @@ -1,6 +1,5 @@ -Connect-JCOnlineTest Describe -Tag:('JCUserGroupMember') 'Get-JCUserGroupMember 1.0' { - + Connect-JCOnlineTest It 'Gets a User Groups membership by Groupname' { $UserGroupMembers = Get-JCUserGroupMember -GroupName $PesterParams.UserGroupName $UserGroupMembers.id.Count | Should -BeGreaterThan 0 diff --git a/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/New-JCUserGroup.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/New-JCUserGroup.tests.ps1 index 248a53351..563dcb549 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/New-JCUserGroup.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/New-JCUserGroup.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCUserGroup') 'New-JCUserGroup 1.0' { - + Connect-JCOnlineTest It "Creates a new user group" { $NewG = New-JCUserGroup -GroupName $(New-RandomString 8) $NewG.Result | Should -Be 'Created' diff --git a/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Remove-JCUserGroup.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Remove-JCUserGroup.tests.ps1 index 11b45bfc4..46c48a2f5 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Remove-JCUserGroup.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Remove-JCUserGroup.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCUserGroup') 'New-JCUserGroup 1.0' { - + Connect-JCOnlineTest It "Creates a new user group" { $NewG = New-JCUserGroup -GroupName $(New-RandomString 8) $DeletedG = Remove-JCUserGroup -GroupName $NewG.name -force diff --git a/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Remove-JCUserGroupMember.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Remove-JCUserGroupMember.tests.ps1 index 0287e5680..10dc0e2b1 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Remove-JCUserGroupMember.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Remove-JCUserGroupMember.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCUserGroupMember') 'Remove-JCUserGroupMember 1.0' { - + Connect-JCOnlineTest It "Removes JumpCloud user from a JumpCloud user group by User GroupName and Username" { $SingleUserGroupAdd = Add-JCUserGroupMember -GroupName $PesterParams.UserGroupName -username $PesterParams.Username diff --git a/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Set-JCUserGroupLDAP.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Set-JCUserGroupLDAP.tests.ps1 index 7c5db6538..a150bf67c 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Set-JCUserGroupLDAP.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Groups/UserGroups/Set-JCUserGroupLDAP.tests.ps1 @@ -1,8 +1,5 @@ - -Connect-JCOnlineTest - Describe -Tag:('JCUserGroupLDAP') 'Set-JCUserGroupLDAP' { - + Connect-JCOnlineTest It "Enables LDAP for a JumpCloud User Group using GroupName" { $NewUserGroup = New-JCUserGroup -GroupName $(New-RandomString 8) | Select-Object -ExpandProperty Name diff --git a/PowerShell/JumpCloud Module/Tests/Public/Policies/Get-JCPolicy.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Policies/Get-JCPolicy.tests.ps1 index 94c84315a..940b4deee 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Policies/Get-JCPolicy.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Policies/Get-JCPolicy.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCPolicy') 'Get-JCPolicy 1.10' { - + Connect-JCOnlineTest It "Returns a single JumpCloud Policy declaring -PolicyId" { $SingleResult = Get-JCPolicy -PolicyId:($SinglePolicy.id) $SingleResult.id.Count | Should Be $SinglePolicyList.Count diff --git a/PowerShell/JumpCloud Module/Tests/Public/Policies/PolicyResults/Get-JCPolicyResult.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Policies/PolicyResults/Get-JCPolicyResult.tests.ps1 index be762afba..eb7820ca2 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Policies/PolicyResults/Get-JCPolicyResult.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Policies/PolicyResults/Get-JCPolicyResult.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCPolicyResult') "Get-JCPolicyResult 1.10" { - + Connect-JCOnlineTest It "Returns a policy result with the PolicyName" { $PolicyResult = Get-JCPolicyResult $SinglePolicy.Name $PolicyResult.count | Should -BeGreaterThan 0 diff --git a/PowerShell/JumpCloud Module/Tests/Public/Policies/PolicyTargets/Get-JCPolicyTargetGroup.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Policies/PolicyTargets/Get-JCPolicyTargetGroup.tests.ps1 index d99577817..c4f64cb16 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Policies/PolicyTargets/Get-JCPolicyTargetGroup.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Policies/PolicyTargets/Get-JCPolicyTargetGroup.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCPolicyTargetGroup') 'Get-JCPolicyTargetGroup 1.10' { - + Connect-JCOnlineTest It "Returns all JumpCloud policy group targets by GroupName using PolicyId" { $SystemGroupTarget = Get-JCPolicyTargetGroup -PolicyId:($SinglePolicy.id) $SystemGroupTarget.GroupName.count | Should -BeGreaterThan 0 diff --git a/PowerShell/JumpCloud Module/Tests/Public/Policies/PolicyTargets/Get-JCPolicyTargetSystem.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Policies/PolicyTargets/Get-JCPolicyTargetSystem.tests.ps1 index a06356236..2265591d4 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Policies/PolicyTargets/Get-JCPolicyTargetSystem.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Policies/PolicyTargets/Get-JCPolicyTargetSystem.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCPolicyTargetSystem') 'Get-JCPolicyTargetSystem 1.10' { - + Connect-JCOnlineTest It "Returns all JumpCloud policy system targets using PolicyId" { $SystemTarget = Get-JCPolicyTargetSystem -PolicyId:($SinglePolicy.id) $SystemTarget.SystemID.count | Should -BeGreaterThan 0 diff --git a/PowerShell/JumpCloud Module/Tests/Public/Radius/Add-JCRadiusReplyAttribute.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Radius/Add-JCRadiusReplyAttribute.tests.ps1 index 3becea513..235cec175 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Radius/Add-JCRadiusReplyAttribute.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Radius/Add-JCRadiusReplyAttribute.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCRadiusReplyAttribute') "Add-JCRadiusReplyAttribute 1.9.0" { - + Connect-JCOnlineTest It "Adds VLAN attributes to a group" { $NewGroup = New-JCUserGroup -GroupName $(New-RandomStringLower) diff --git a/PowerShell/JumpCloud Module/Tests/Public/Radius/Get-JCRadiusReplyAttribute.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Radius/Get-JCRadiusReplyAttribute.tests.ps1 index 637aa69d5..250939c74 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Radius/Get-JCRadiusReplyAttribute.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Radius/Get-JCRadiusReplyAttribute.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCRadiusReplyAttribute') "Get-JCRadiusReplyAttribute 1.9.0" { - + Connect-JCOnlineTest It "Adds VLAN attributes to a group and uses Get-JCRadiusReplyAttributes to verify" { $NewGroup = New-JCUserGroup -GroupName $(New-RandomStringLower) diff --git a/PowerShell/JumpCloud Module/Tests/Public/Radius/Remove-JCRadiusReplyAttribute.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Radius/Remove-JCRadiusReplyAttribute.tests.ps1 index d159c05e4..acbf46635 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Radius/Remove-JCRadiusReplyAttribute.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Radius/Remove-JCRadiusReplyAttribute.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCRadiusReplyAttribute') "Remove-JCRadiusReplyAttributes 1.9.0" { - + Connect-JCOnlineTest It "Removes a single custom radius attribute from a group" { $NewGroup = New-JCUserGroup -GroupName $(New-RandomStringLower) diff --git a/PowerShell/JumpCloud Module/Tests/Public/Radius/Set-JCRadiusReplyAttribute.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Radius/Set-JCRadiusReplyAttribute.tests.ps1 index 409ac94da..2f1a99da3 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Radius/Set-JCRadiusReplyAttribute.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Radius/Set-JCRadiusReplyAttribute.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCRadiusReplyAttribute') "Set-JCRadiusReplyAttribute 1.9.0" { - + Connect-JCOnlineTest It "Updates VLAN attributes on a group" { $NewGroup = New-JCUserGroup -GroupName $(New-RandomStringLower) diff --git a/PowerShell/JumpCloud Module/Tests/Public/SystemUsers/Add-JCSystemUser.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/SystemUsers/Add-JCSystemUser.tests.ps1 index b8e6d756d..6eccbcf17 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/SystemUsers/Add-JCSystemUser.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/SystemUsers/Add-JCSystemUser.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCSystemUser') 'Add-JCSystemUser 1.0' { - + Connect-JCOnlineTest It "Adds a single user to a single system by Username and SystemID" { $UserRemove = Remove-JCSystemUser -Username $PesterParams.Username -SystemID $PesterParams.SystemID -force $UserAdd = Add-JCSystemUser -Username $PesterParams.Username -SystemID $PesterParams.SystemID diff --git a/PowerShell/JumpCloud Module/Tests/Public/SystemUsers/Get-JCSystemUser.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/SystemUsers/Get-JCSystemUser.tests.ps1 index 256f2de23..4d61da704 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/SystemUsers/Get-JCSystemUser.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/SystemUsers/Get-JCSystemUser.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCSystemUser') 'Get-JCSystemUser 1.0' { - + Connect-JCOnlineTest It "Gets JumpCloud system users for a system using SystemID" { $SystemUsers = Get-JCSystemUser -SystemID $PesterParams.SystemID diff --git a/PowerShell/JumpCloud Module/Tests/Public/SystemUsers/Remove-JCSystemUser.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/SystemUsers/Remove-JCSystemUser.tests.ps1 index 050c8dea1..7125e0e3f 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/SystemUsers/Remove-JCSystemUser.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/SystemUsers/Remove-JCSystemUser.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCSystemUser') 'Remove-JCSystemUser 1.0' { - + Connect-JCOnlineTest It "Adds a single user to a single system by Username and SystemID" { $UserRemove = Remove-JCSystemUser -Username $PesterParams.Username -SystemID $PesterParams.SystemID -force $UserAdd = Add-JCSystemUser -Username $PesterParams.Username -SystemID $PesterParams.SystemID diff --git a/PowerShell/JumpCloud Module/Tests/Public/SystemUsers/Set-JCSystemUser.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/SystemUsers/Set-JCSystemUser.tests.ps1 index cae3e7fd9..fa3257284 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/SystemUsers/Set-JCSystemUser.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/SystemUsers/Set-JCSystemUser.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCSystemUser') 'Set-JCSystemUser 1.0' { - + Connect-JCOnlineTest It "Sets a standard user to an admin user using username" { Add-JCSystemUser -SystemID $PesterParams.SystemID -Username $PesterParams.Username -Administrator $False #Sets to standard user diff --git a/PowerShell/JumpCloud Module/Tests/Public/Systems/Get-JCSystem.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Systems/Get-JCSystem.tests.ps1 index 84dfd3cad..0fdcebb58 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Systems/Get-JCSystem.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Systems/Get-JCSystem.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCSystem') 'Get-JCSystem 1.0' { - + Connect-JCOnlineTest It "Gets all JumpCloud systems" { $Systems = Get-JCSystem $Systems._id.Count | Should -BeGreaterThan 1 diff --git a/PowerShell/JumpCloud Module/Tests/Public/Systems/Get-JCSystemInsights.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Systems/Get-JCSystemInsights.Tests.ps1 new file mode 100644 index 000000000..1fea6f8f8 --- /dev/null +++ b/PowerShell/JumpCloud Module/Tests/Public/Systems/Get-JCSystemInsights.Tests.ps1 @@ -0,0 +1,107 @@ +$FileBaseName = (Get-Item -Path:($MyInvocation.MyCommand.Path)).BaseName +Describe -Tag:('JCSystemInsights') "Get-JCSystemInsights Tests" { + BeforeAll { + # $DebugPreference = 'Continue' # SilentlyContinue (Default), Continue, Inquire, Stop + # $VerbosePreference = 'Continue' # SilentlyContinue (Default), Continue, Inquire, Stop + $ErrorActionPreference = 'Stop' # Continue (Default), Ignore, Inquire, SilentlyContinue, Stop, Suspend + } + AfterAll { + # $DebugPreference = 'SilentlyContinue' # SilentlyContinue (Default), Continue, Inquire, Stop + # $VerbosePreference = 'SilentlyContinue' # SilentlyContinue (Default), Continue, Inquire, Stop + $ErrorActionPreference = 'Continue' # Continue (Default), Ignore, Inquire, SilentlyContinue, Stop, Suspend + } + # Retrieve objects to test with + $Type = 'system' + $JCType = Get-JCType -Type:($Type) + $Tables = $JCType.SystemInsights.Table + $JCObject = Get-JCObject -Type:($Type) -Fields:($JCType.ById, $JCType.ByName, 'systemInsights') | Where-Object {$_.systemInsights.state -eq 'enabled' -and $_.displayName -ne 'Dwights-MacBook-Pro.local'} #-Limit:(2) -Paginate:($false) + # Define misc. variables + $Mock = $false + $MockFilePath = $PSScriptRoot + '/MockCommands_' + $FileBaseName + '.ps1' + $TestMethods = ('ById', 'ByName') + # Remove mock file if exists + If ($Mock) {If (Test-Path -Path:($MockFilePath)) {Remove-Item -Path:($MockFilePath) -Force}} + # Run tests + If (-not ([System.String]::IsNullOrEmpty($JCObject))) + { + ForEach ($Table In $Tables) + { + Context ('Tests returning records of a specific table across all systems.') { + $Command = "Get-JCSystemInsights -Table`:('$Table');" + Context ("Running command: $Command") { + If ($Mock) + { + $Command | Tee-Object -FilePath:($MockFilePath) -Append + } + Else + { + $CommandResults = Invoke-Expression -Command:($Command) -ErrorVariable:('CommandResultsError') + # It("Where results should be not NullOrEmpty") {$CommandResults | Should -Not -BeNullOrEmpty} + It("Where Error is NullOrEmpty") {$CommandResultsError | Should -BeNullOrEmpty} + } + } + } + Context ('Tests returning records of a specific table across specified systems.') { + ForEach ($TestMethod In $TestMethods) + { + $TestMethodIdentifier = $TestMethod.Replace('By', '') + $ById = $JCObject.($JCObject.ById | Select-Object -Unique) + $ByName = $JCObject.($JCObject.ByName | Select-Object -Unique) + $SearchByValue = Switch ($TestMethod) + { + 'ById' { $ById } + 'ByName' { $ByName } + Default { Write-Error ('Unknown $TestMethod: "' + $TestMethod + '"') } + } + $SingleJCItem = "'" + (($SearchByValue | Select-Object -First 1) -join "', '") + "'" + $MultipleJCItem = "'" + (($SearchByValue | Select-Object -First 2) -join "', '") + "'" + Context ("Testing by: $TestMethod'") { + $CommandRecords = @() + # Test using the -Id and -Name parameters with single item + $CommandRecords += [PSCustomObject]@{ 'TestType' = 'Single'; 'Command' = "Get-JCSystemInsights -Table`:('$Table') -$TestMethodIdentifier`:($SingleJCItem);"; } + # Test using the -SearchBy and -SearchByValue parameters with single item + $CommandRecords += [PSCustomObject]@{ 'TestType' = 'Single'; 'Command' = "Get-JCSystemInsights -Table`:('$Table') -SearchBy`:('$TestMethod') -SearchByValue`:($SingleJCItem);"; } + # Test using the -Id and -Name parameters with multiple items + $CommandRecords += [PSCustomObject]@{ 'TestType' = 'Multiple'; 'Command' = "Get-JCSystemInsights -Table`:('$Table') -$TestMethodIdentifier`:($MultipleJCItem);"; } + # Test using the -SearchBy and -SearchByValue parameters with multiple items + $CommandRecords += [PSCustomObject]@{ 'TestType' = 'Multiple'; 'Command' = "Get-JCSystemInsights -Table`:('$Table') -SearchBy`:('$TestMethod') -SearchByValue`:($MultipleJCItem);"; } + ForEach ($CommandRecord In $CommandRecords) + { + $TestType = $CommandRecord.TestType + $Command = $CommandRecord.Command + Context ("Running command: $Command") { + If ($Mock) + { + $Command | Tee-Object -FilePath:($MockFilePath) -Append + } + Else + { + $CommandResults = Invoke-Expression -Command:($Command) -ErrorVariable:('CommandResultsError') + It("Where Error is NullOrEmpty") {$CommandResultsError | Should -BeNullOrEmpty} + # It("Where results should be not NullOrEmpty") {$CommandResults | Should -Not -BeNullOrEmpty} + # Switch ($TestType) + # { + # 'Single' + # { + # It("Where unique object id count should Be 1") {($CommandResults.jc_system_id | Select-Object -Unique | Measure-Object).Count | Should -Be 1} + # } + # 'Multiple' + # { + # It("Where unique object id count should BeGreaterThan 1") {($CommandResults.jc_system_id | Select-Object -Unique | Measure-Object).Count | Should -BeGreaterThan 1} + # } + # Default {Write-Error 'Unknown $TestType: "' + $TestType + '"'} + # } + # It("Where results '$($CommandResults.($CommandResults.ById | Select-Object -Unique) | Select-Object -Unique)' should BeIn '$ById'") {$CommandResults.($CommandResults.ById | Select-Object -Unique) | Select-Object -Unique | Should -BeIn $ById} + } + } + } + } + } + } + } + } + Else + { + Throw 'Command returned no JCObjects to test with.' + } +} \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Tests/Public/Systems/Set-JCSystem.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Systems/Set-JCSystem.tests.ps1 index b864c6fb6..f7f5a86ff 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Systems/Set-JCSystem.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Systems/Set-JCSystem.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCSystem') 'Set-JCSystem 1.0' { - + Connect-JCOnlineTest It "Updates the DisplyName and then set it back" { $CurrentDisplayName = Get-JCSystem -SystemID $PesterParams.SystemID | Select-Object DisplayName $UpdatedSystem = Set-JCSystem -SystemID $PesterParams.SystemID -displayName 'NewName' diff --git a/PowerShell/JumpCloud Module/Tests/Public/Users/Get-JCUser.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Users/Get-JCUser.tests.ps1 index 83b4409ef..b45f45090 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Users/Get-JCUser.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Users/Get-JCUser.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCUser') 'Get-JCUser 1.0' { - + Connect-JCOnlineTest It "Gets all JumpCloud users using Get-JCuser" { $Users = Get-JCUser $Users._id.count | Should -BeGreaterThan 1 } diff --git a/PowerShell/JumpCloud Module/Tests/Public/Users/New-JCUser.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Users/New-JCUser.tests.ps1 index 82f3bdd54..3847fec13 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Users/New-JCUser.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Users/New-JCUser.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCUser') 'New-JCUser 1.0' { - +Connect-JCOnlineTest It "Creates a new user" { $NewUser = New-RandomUser -domain pleasedelete"PesterTest$(Get-Date -Format MM-dd-yyyy)" | New-JCUser $NewUser._id.count | Should -Be 1 @@ -494,14 +492,8 @@ Describe -Tag:('JCUser') "New-JCUser MFA with enrollment periods 1.10" { $Newuser = New-RandomUser -domain "deleteme" | New-JCUser -enable_user_portal_multifactor $true - $DateCheck = (Get-Date).AddDays(7).AddHours(7) # +7 hours for UTC offset - $Newuser.mfa.exclusion | Should -Be $true - $DateConfirm = New-TimeSpan -Start $Newuser.mfa.exclusionUntil -End $DateCheck - - $DateConfirm.Seconds | Should -BeLessThan 2 - $Newuser | Remove-JCUser -ByID -force } @@ -512,14 +504,8 @@ Describe -Tag:('JCUser') "New-JCUser MFA with enrollment periods 1.10" { $Newuser = New-RandomUser -domain "deleteme" | New-JCUser -enable_user_portal_multifactor $true -EnrollmentDays $EnrollmentDays - $DateCheck = (Get-Date).AddDays($EnrollmentDays).AddHours(7) # +7 hours for UTC offset - $Newuser.mfa.exclusion | Should -Be $true - $DateConfirm = New-TimeSpan -Start $Newuser.mfa.exclusionUntil -End $DateCheck - - $DateConfirm.Seconds | Should -BeLessThan 2 - $Newuser | Remove-JCUser -ByID -force } @@ -530,14 +516,8 @@ Describe -Tag:('JCUser') "New-JCUser MFA with enrollment periods 1.10" { $Newuser = New-RandomUser -domain "deleteme" | New-JCUser -enable_user_portal_multifactor $true -EnrollmentDays $EnrollmentDays - $DateCheck = (Get-Date).AddDays($EnrollmentDays).AddHours(7) # +7 hours for UTC offset - $Newuser.mfa.exclusion | Should -Be $true - $DateConfirm = New-TimeSpan -Start $Newuser.mfa.exclusionUntil -End $DateCheck - - $DateConfirm.Seconds | Should -BeLessThan 2 - $Newuser | Remove-JCUser -ByID -force } @@ -547,14 +527,8 @@ Describe -Tag:('JCUser') "New-JCUser MFA with enrollment periods 1.10" { $NewUser = New-RandomUser -domain "deleteme"-Attributes | New-JCUser -NumberOfCustomAttributes 2 -enable_user_portal_multifactor $True - $DateCheck = (Get-Date).AddDays(7).AddHours(7) # +7 hours for UTC offset - $Newuser.mfa.exclusion | Should -Be $true - $DateConfirm = New-TimeSpan -Start $Newuser.mfa.exclusionUntil -End $DateCheck - - $DateConfirm.Seconds | Should -BeLessThan 2 - $Newuser | Remove-JCUser -ByID -force } @@ -565,14 +539,8 @@ Describe -Tag:('JCUser') "New-JCUser MFA with enrollment periods 1.10" { $NewUser = New-RandomUser -domain "deleteme"-Attributes | New-JCUser -NumberOfCustomAttributes 2 -enable_user_portal_multifactor $True -EnrollmentDays $EnrollmentDays - $DateCheck = (Get-Date).AddDays($EnrollmentDays).AddHours(7) # +7 hours for UTC offset - $Newuser.mfa.exclusion | Should -Be $true - $DateConfirm = New-TimeSpan -Start $Newuser.mfa.exclusionUntil -End $DateCheck - - $DateConfirm.Seconds | Should -BeLessThan 2 - $Newuser | Remove-JCUser -ByID -force } @@ -596,14 +564,8 @@ Describe -Tag:('JCUser') "New-JCUser MFA with enrollment periods 1.10" { $NewUser = $newUserObj | % { New-JCUser -enable_user_portal_multifactor $_.enable_user_portal_multifactor -EnrollmentDays $_.EnrollmentDays -firstName $_.firstName -lastName $_.Lastname -username $_.username -email $_.email } - $DateCheck = (Get-Date).AddDays($EnrollmentDays).AddHours(7) # +7 hours for UTC offset - $Newuser.mfa.exclusion | Should -Be $true - $DateConfirm = New-TimeSpan -Start $Newuser.mfa.exclusionUntil -End $DateCheck - - $DateConfirm.Seconds | Should -BeLessThan 2 - $Newuser | Remove-JCUser -ByID -force } diff --git a/PowerShell/JumpCloud Module/Tests/Public/Users/Remove-JCUser.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Users/Remove-JCUser.tests.ps1 index 22ccf1795..b841b68cd 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Users/Remove-JCUser.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Users/Remove-JCUser.tests.ps1 @@ -1,13 +1,11 @@ -Connect-JCOnlineTest - -It "Remove-JCUser 1.0" { - $NewUser = New-RandomUser "PesterTest$(Get-Date -Format MM-dd-yyyy)" | New-JCUser - $DeleteUser = Remove-JCUser -UserID $NewUser._id -ByID -Force - $DeleteUser.results | Should -be 'Deleted' -} - - Describe -Tag:('JCUser') "Remove-JCUser 1.10" { + Connect-JCOnlineTest + + It "Remove-JCUser 1.0" { + $NewUser = New-RandomUser "PesterTest$(Get-Date -Format MM-dd-yyyy)" | New-JCUser + $DeleteUser = Remove-JCUser -UserID $NewUser._id -ByID -Force + $DeleteUser.results | Should -be 'Deleted' + } It "Removes JumpCloud User by Username and -force" { diff --git a/PowerShell/JumpCloud Module/Tests/Public/Users/Set-JCUser.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Users/Set-JCUser.tests.ps1 index 7c2cf237d..cc3c3064b 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Users/Set-JCUser.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Users/Set-JCUser.tests.ps1 @@ -1,8 +1,5 @@ - -Connect-JCOnlineTest - Describe -Tag:('JCUser') 'Set-JCUser 1.0' { - + Connect-JCOnlineTest It "Updates the firstname using -ByID and -UserID" { $NewUser = New-RandomUser "PesterTest$(Get-Date -Format MM-dd-yyyy)" | New-JCUser @@ -1495,14 +1492,8 @@ Describe -Tag:('JCUser') "Set-JCUser MFA Enrollment periods 1.10" { $NewUser = $CreateUser | Set-JCUser -enable_user_portal_multifactor $true - $DateCheck = (Get-Date).AddDays(7).AddHours(7) # +7 hours for UTC offset - $Newuser.mfa.exclusion | Should -Be $true - $DateConfirm = New-TimeSpan -Start $Newuser.mfa.exclusionUntil -End $DateCheck - - $DateConfirm.Seconds | Should -BeLessThan 2 - $Newuser | Remove-JCUser -ByID -force } @@ -1515,14 +1506,8 @@ Describe -Tag:('JCUser') "Set-JCUser MFA Enrollment periods 1.10" { $NewUser = $CreateUser | Set-JCUser -enable_user_portal_multifactor $true -EnrollmentDays $EnrollmentDays - $DateCheck = (Get-Date).AddDays($EnrollmentDays).AddHours(7) # +7 hours for UTC offset - $Newuser.mfa.exclusion | Should -Be $true - $DateConfirm = New-TimeSpan -Start $Newuser.mfa.exclusionUntil -End $DateCheck - - $DateConfirm.Seconds | Should -BeLessThan 2 - $Newuser | Remove-JCUser -ByID -force @@ -1536,14 +1521,8 @@ Describe -Tag:('JCUser') "Set-JCUser MFA Enrollment periods 1.10" { $NewUser = $CreateUser | Set-JCUser -enable_user_portal_multifactor $true -EnrollmentDays $EnrollmentDays - $DateCheck = (Get-Date).AddDays($EnrollmentDays).AddHours(7) # +7 hours for UTC offset - $Newuser.mfa.exclusion | Should -Be $true - $DateConfirm = New-TimeSpan -Start $Newuser.mfa.exclusionUntil -End $DateCheck - - $DateConfirm.Seconds | Should -BeLessThan 2 - $Newuser | Remove-JCUser -ByID -force } @@ -1552,14 +1531,8 @@ Describe -Tag:('JCUser') "Set-JCUser MFA Enrollment periods 1.10" { $NewUser = $CreateUser | Set-JCUser -enable_user_portal_multifactor $true -ByID - $DateCheck = (Get-Date).AddDays(7).AddHours(7) # +7 hours for UTC offset - $Newuser.mfa.exclusion | Should -Be $true - $DateConfirm = New-TimeSpan -Start $Newuser.mfa.exclusionUntil -End $DateCheck - - $DateConfirm.Seconds | Should -BeLessThan 2 - $Newuser | Remove-JCUser -ByID -force } @@ -1572,14 +1545,8 @@ Describe -Tag:('JCUser') "Set-JCUser MFA Enrollment periods 1.10" { $NewUser = $CreateUser | Set-JCUser -enable_user_portal_multifactor $true -EnrollmentDays $EnrollmentDays -ByID - $DateCheck = (Get-Date).AddDays($EnrollmentDays).AddHours(7) # +7 hours for UTC offset - $Newuser.mfa.exclusion | Should -Be $true - $DateConfirm = New-TimeSpan -Start $Newuser.mfa.exclusionUntil -End $DateCheck - - $DateConfirm.Seconds | Should -BeLessThan 2 - $Newuser | Remove-JCUser -ByID -force @@ -1593,14 +1560,8 @@ Describe -Tag:('JCUser') "Set-JCUser MFA Enrollment periods 1.10" { $NewUser = $CreateUser | Set-JCUser -enable_user_portal_multifactor $true -EnrollmentDays $EnrollmentDays -ByID - $DateCheck = (Get-Date).AddDays($EnrollmentDays).AddHours(7) # +7 hours for UTC offset - $Newuser.mfa.exclusion | Should -Be $true - $DateConfirm = New-TimeSpan -Start $Newuser.mfa.exclusionUntil -End $DateCheck - - $DateConfirm.Seconds | Should -BeLessThan 2 - $Newuser | Remove-JCUser -ByID -force } @@ -1611,14 +1572,8 @@ Describe -Tag:('JCUser') "Set-JCUser MFA Enrollment periods 1.10" { $NewUser = $CreateUser | Set-JCUser -enable_user_portal_multifactor $true -NumberOfCustomAttributes 1 -Attribute1_name 'attr1' -Attribute1_value 'attr1v' - $DateCheck = (Get-Date).AddDays(7).AddHours(7) # +7 hours for UTC offset - $Newuser.mfa.exclusion | Should -Be $true - $DateConfirm = New-TimeSpan -Start $Newuser.mfa.exclusionUntil -End $DateCheck - - $DateConfirm.Seconds | Should -BeLessThan 2 - $Newuser | Remove-JCUser -ByID -force } @@ -1631,14 +1586,8 @@ Describe -Tag:('JCUser') "Set-JCUser MFA Enrollment periods 1.10" { $NewUser = $CreateUser | Set-JCUser -enable_user_portal_multifactor $true -EnrollmentDays $EnrollmentDays -NumberOfCustomAttributes 1 -Attribute1_name 'attr1' -Attribute1_value 'attr1v' - $DateCheck = (Get-Date).AddDays($EnrollmentDays).AddHours(7) # +7 hours for UTC offset - $Newuser.mfa.exclusion | Should -Be $true - $DateConfirm = New-TimeSpan -Start $Newuser.mfa.exclusionUntil -End $DateCheck - - $DateConfirm.Seconds | Should -BeLessThan 2 - $Newuser | Remove-JCUser -ByID -force @@ -1650,14 +1599,8 @@ Describe -Tag:('JCUser') "Set-JCUser MFA Enrollment periods 1.10" { $NewUser = $CreateUser | Set-JCUser -enable_user_portal_multifactor $true -RemoveAttribute 'Department', 'Lang' - $DateCheck = (Get-Date).AddDays(7).AddHours(7) # +7 hours for UTC offset - $Newuser.mfa.exclusion | Should -Be $true - $DateConfirm = New-TimeSpan -Start $Newuser.mfa.exclusionUntil -End $DateCheck - - $DateConfirm.Seconds | Should -BeLessThan 2 - $Newuser | Remove-JCUser -ByID -force } @@ -1669,14 +1612,8 @@ Describe -Tag:('JCUser') "Set-JCUser MFA Enrollment periods 1.10" { $NewUser = $CreateUser | Set-JCUser -enable_user_portal_multifactor $true -EnrollmentDays $EnrollmentDays - $DateCheck = (Get-Date).AddDays($EnrollmentDays).AddHours(7) # +7 hours for UTC offset - $Newuser.mfa.exclusion | Should -Be $true - $DateConfirm = New-TimeSpan -Start $Newuser.mfa.exclusionUntil -End $DateCheck - - $DateConfirm.Seconds | Should -BeLessThan 2 - $Newuser | Remove-JCUser -ByID -force diff --git a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCUsersFromCSV.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCUsersFromCSV.tests.ps1 index c0962ec17..f3bd05f07 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCUsersFromCSV.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCUsersFromCSV.tests.ps1 @@ -1,11 +1,7 @@ -Connect-JCOnlineTest - Describe -Tag:('JCUsersFromCSV') 'Import-JCUserFromCSV 1.1' { - + Connect-JCOnlineTest It "Imports users from the ImportExample_Pester_Test using -Force" { - - $UserImport = Import-JCUsersFromCSV -CSVFilePath $Import_JCUsersFromCSV_1_1_Tests -force - + $UserImport = Import-JCUsersFromCSV -CSVFilePath $Import_JCUsersFromCSV_1_1_Tests -force } @@ -363,12 +359,8 @@ Describe -Tag:('JCUsersFromCSV') 'Import-JCUserFromCSV 1.1' { } - + Get-JCUser | Where-Object Email -like *pleasedelete* | Remove-JCUser -force } - -Get-JCUser | Where-Object Email -like *pleasedelete* | Remove-JCUser -force - - Describe -Tag:('JCUsersFromCSV') "Import-JCUsersFromCSV 1.8.0" { It "Imports users from a CSV populated with telephony attributes" { @@ -450,8 +442,8 @@ Describe -Tag:('JCUsersFromCSV') "Import-JCUsersFromCSV 1.8.0" { It "Imports users from a CSV populated with telephony, location, and user information attributes" { - $UserCSVImport = Import-JCUsersFromCSV -CSVFilePath $ImportPath/ImportExample_AllNewAttributes.csv -force - $UserImportInfo = Import-Csv $ImportPath/ImportExample_AllNewAttributes.csv + $UserCSVImport = Import-JCUsersFromCSV -CSVFilePath $ImportPath/ImportExample_allNewAttributes.csv -force + $UserImportInfo = Import-Csv $ImportPath/ImportExample_allNewAttributes.csv foreach ($User in $UserCSVImport) { @@ -496,8 +488,8 @@ Describe -Tag:('JCUsersFromCSV') "Import-JCUsersFromCSV 1.8.0" { It "Imports users from a CSV populated with telephony, location, user information attributes, group additions, system binding, and custom attributes" { - $UserCSVImport = Import-JCUsersFromCSV -CSVFilePath $ImportPath/ImportExample_AllNewAttributesAndAllCustom.csv -force - $UserImportInfo = Import-Csv $ImportPath/ImportExample_AllNewAttributesAndAllCustom.csv + $UserCSVImport = Import-JCUsersFromCSV -CSVFilePath $ImportPath/ImportExample_allNewAttributesAndAllCustom.csv -force + $UserImportInfo = Import-Csv $ImportPath/ImportExample_allNewAttributesAndAllCustom.csv foreach ($User in $UserCSVImport) { diff --git a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/New-JCImportTemplate.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/New-JCImportTemplate.tests.ps1 index e69de29bb..7e2a145f0 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/New-JCImportTemplate.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/New-JCImportTemplate.tests.ps1 @@ -0,0 +1 @@ +# Ticket created to populate tests: SA-469 \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.tests.ps1 index a82270608..722fa2cfb 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCUsersFromCSV') "Update-JCUsersFromCSV 1.8.0" { - + Connect-JCOnlineTest It "Updates users from a CSV populated with telephony attributes" { $UserCSVImport = Import-JCUsersFromCSV -CSVFilePath $ImportPath/ImportExample_telephonyAttributes.csv -force @@ -135,8 +133,8 @@ Describe -Tag:('JCUsersFromCSV') "Update-JCUsersFromCSV 1.8.0" { It "Updates users from a CSV populated with user telephony, information, and location attributes" { - $UserCSVImport = Import-JCUsersFromCSV -CSVFilePath $ImportPath/ImportExample_AllNewAttributes.csv -force - $UserImportInfo = Import-Csv $ImportPath/ImportExample_AllNewAttributes.csv + $UserCSVImport = Import-JCUsersFromCSV -CSVFilePath $ImportPath/ImportExample_allNewAttributes.csv -force + $UserImportInfo = Import-Csv $ImportPath/ImportExample_allNewAttributes.csv foreach ($User in $UserCSVImport) { @@ -177,7 +175,7 @@ Describe -Tag:('JCUsersFromCSV') "Update-JCUsersFromCSV 1.8.0" { } $UserUpdateCSVImport = Update-JCUsersFromCSV -CSVFilePath $UpdatePath/UpdateExample_AllNewAttributes.csv -force - $UserUpdateInfo = Import-Csv $UpdatePath/UpdateExample_AllNewAttributes.csv + $UserUpdateInfo = Import-Csv $UpdatePath/UpdateExample_AllNewAttributes.csv foreach ($UpdateUser in $UserUpdateCSVImport) { @@ -223,8 +221,8 @@ Describe -Tag:('JCUsersFromCSV') "Update-JCUsersFromCSV 1.8.0" { It "Updates users from a CSV populated with user telephony, information, and location attributes and custom attributes" { - $UserCSVImport = Import-JCUsersFromCSV -CSVFilePath $ImportPath/ImportExample_AllNewAttributesAndAllCustom.csv -force - $UserImportInfo = Import-Csv $ImportPath/ImportExample_AllNewAttributesAndAllCustom.csv + $UserCSVImport = Import-JCUsersFromCSV -CSVFilePath $ImportPath/ImportExample_allNewAttributesAndAllCustom.csv -force + $UserImportInfo = Import-Csv $ImportPath/ImportExample_allNewAttributesAndAllCustom.csv foreach ($User in $UserCSVImport) { @@ -265,7 +263,7 @@ Describe -Tag:('JCUsersFromCSV') "Update-JCUsersFromCSV 1.8.0" { } $UserUpdateCSVImport = Update-JCUsersFromCSV -CSVFilePath $UpdatePath/UpdateExample_AllNewAttributesAndAllCustom.csv -force - $UserUpdateInfo = Import-Csv $UpdatePath/UpdateExample_AllNewAttributesAndAllCustom.csv + $UserUpdateInfo = Import-Csv $UpdatePath/UpdateExample_AllNewAttributesAndAllCustom.csv foreach ($UpdateUser in $UserUpdateCSVImport) { @@ -320,8 +318,8 @@ Describe -Tag:('JCUsersFromCSV') "Update-JCUsersFromCSV 1.8.0" { It "Updates users from a CSV populated with no information" { - $UserCSVImport = Import-JCUsersFromCSV -CSVFilePath $ImportPath/ImportExample_AllNewAttributesAndAllCustom.csv -force - $UserImportInfo = Import-Csv $ImportPath/ImportExample_AllNewAttributesAndAllCustom.csv + $UserCSVImport = Import-JCUsersFromCSV -CSVFilePath $ImportPath/ImportExample_allNewAttributesAndAllCustom.csv -force + $UserImportInfo = Import-Csv $ImportPath/ImportExample_allNewAttributesAndAllCustom.csv foreach ($User in $UserCSVImport) { diff --git a/PowerShell/JumpCloud Module/Tests/Public/Utilities/Get-JCBackup.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Utilities/Get-JCBackup.tests.ps1 index 2984b0aa5..1c6c5d4d9 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Utilities/Get-JCBackup.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Utilities/Get-JCBackup.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCBackup') "Get-JCBackup 1.5.0" { - + Connect-JCOnlineTest It "Backs up JumpCloud users" { Get-JCBackup -All diff --git a/PowerShell/JumpCloud Module/Tests/Public/Utilities/Send-JCPasswordReset.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Utilities/Send-JCPasswordReset.tests.ps1 index 6167de6bb..391ce6dd1 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Utilities/Send-JCPasswordReset.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Utilities/Send-JCPasswordReset.tests.ps1 @@ -1,7 +1,5 @@ -Connect-JCOnlineTest - Describe -Tag:('JCPasswordReset') "Sent-JCPasswordReset 1.6.0" { - + Connect-JCOnlineTest It "Sends a single password reset email by username" { $SingleResetEmail = Send-JCPasswordReset -username $PesterParams.Username diff --git a/PowerShell/JumpCloud Module/Tests/TestEnvironmentVariables.ps1 b/PowerShell/JumpCloud Module/Tests/TestEnvironmentVariables.ps1 index 367d5b93a..053cb4aba 100755 --- a/PowerShell/JumpCloud Module/Tests/TestEnvironmentVariables.ps1 +++ b/PowerShell/JumpCloud Module/Tests/TestEnvironmentVariables.ps1 @@ -1,7 +1,17 @@ -$ModuleManifestName = 'JumpCloud.psd1' -$ModuleManifestPath = "$PSScriptRoot/../$ModuleManifestName" -$TestOrgAPIKey = '' -$MultiTenantAPIKey = '' +# Install Pester +If ($PSVersionTable.PSEdition -eq 'Core') +{ + Install-Module -Name:('Pester') -Force -Scope:('CurrentUser') -SkipPublisherCheck +} +Else +{ + Install-Module -Name:('Pester') -Force -Scope:('CurrentUser') +} +# Import the module +Import-Module -Name:($ModuleManifestPath) -Force +#Load private functions +Get-ChildItem -Path:("$PSScriptRoot/../Private/*.ps1") -Recurse | ForEach-Object {. $_.FullName} +# Set test parameters $PesterParams = @{ # Specific to MTP portal 'MultiTenanntOrgID1' = "5b5a13f06fefdb0a29b0d306" @@ -25,17 +35,11 @@ $PesterParams = @{ $Random = New-RandomString '8' $RandomEmail = "$Random@$Random.com" # CSV Files -$Import_JCUsersFromCSV_1_1_Tests = "$PSScriptRoot/csv_files/import/ImportExample_Pester_Tests_1.1.0.csv" # This CSV file is specific to pester environment (SystemID's and Group Names) +$Import_JCUsersFromCSV_1_1_Tests = "$PSScriptRoot/Csv_Files/import/ImportExample_Pester_Tests_1.1.0.csv" # This CSV file is specific to pester environment (SystemID's and Group Names) $JCDeployment_2_CSV = "$PSScriptRoot/Csv_Files/commandDeployment/JCDeployment_2.csv" $JCDeployment_10_CSV = "$PSScriptRoot/Csv_Files/commandDeployment/JCDeployment_10.csv" -$ImportPath = "$PSScriptRoot/Csv_files/import" -$UpdatePath = "$PSScriptRoot/Csv_files/update" -# Install Pester -Install-Module -Name:('Pester') -Force -Scope:('CurrentUser') -# Import the module -Import-Module -Name:($ModuleManifestPath) -Force -#Load private functions -Get-ChildItem -Path:("$PSScriptRoot/../Private/*.ps1") -Recurse | ForEach-Object {. $_.FullName} +$ImportPath = "$PSScriptRoot/Csv_Files/import" +$UpdatePath = "$PSScriptRoot/Csv_Files/update" # Authenticate to JumpCloud Connect-JCOnlineTest # Policy Info diff --git a/PowerShell/JumpCloud Module/en-Us/.DS_Store b/PowerShell/JumpCloud Module/en-Us/.DS_Store deleted file mode 100644 index ed5934d5c..000000000 Binary files a/PowerShell/JumpCloud Module/en-Us/.DS_Store and /dev/null differ diff --git a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml index 8a4350e2f..cf6e81fc6 100644 --- a/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml +++ b/PowerShell/JumpCloud Module/en-Us/JumpCloud-help.xml @@ -99,7 +99,7 @@ None - + TargetType The type of the target object. @@ -124,6 +124,66 @@ None + + Fields + + An array of the fields/properties/columns you want to return from the search. + + Array + + Array + + + None + + + Filter + + Filters to narrow down search. + + String + + String + + + None + + + Limit + + The number of items you want to return per API call. + + Int32 + + Int32 + + + None + + + Skip + + Ignores the specified number of objects and then gets the remaining objects. Enter the number of objects to skip. + + Int32 + + Int32 + + + None + + + Paginate + + Whether or not you want to paginate through the results. + + Boolean + + Boolean + + + None + Add-JCAssociation @@ -199,7 +259,7 @@ False - + Name The name of the object. @@ -211,7 +271,7 @@ None - + TargetType The type of the target object. @@ -236,6 +296,66 @@ None + + Fields + + An array of the fields/properties/columns you want to return from the search. + + Array + + Array + + + None + + + Filter + + Filters to narrow down search. + + String + + String + + + None + + + Limit + + The number of items you want to return per API call. + + Int32 + + Int32 + + + None + + + Skip + + Ignores the specified number of objects and then gets the remaining objects. Enter the number of objects to skip. + + Int32 + + Int32 + + + None + + + Paginate + + Whether or not you want to paginate through the results. + + Boolean + + Boolean + + + None + @@ -275,7 +395,7 @@ None - + Name The name of the object. @@ -311,7 +431,7 @@ None - + TargetType The type of the target object. @@ -335,6 +455,66 @@ None + + Fields + + An array of the fields/properties/columns you want to return from the search. + + Array + + Array + + + None + + + Filter + + Filters to narrow down search. + + String + + String + + + None + + + Limit + + The number of items you want to return per API call. + + Int32 + + Int32 + + + None + + + Skip + + Ignores the specified number of objects and then gets the remaining objects. Enter the number of objects to skip. + + Int32 + + Int32 + + + None + + + Paginate + + Whether or not you want to paginate through the results. + + Boolean + + Boolean + + + None + @@ -1960,7 +2140,7 @@ None - + TargetType The type of the target object. @@ -2007,6 +2187,66 @@ False + + Fields + + An array of the fields/properties/columns you want to return from the search. + + Array + + Array + + + None + + + Filter + + Filters to narrow down search. + + String + + String + + + None + + + Limit + + The number of items you want to return per API call. + + Int32 + + Int32 + + + None + + + Skip + + Ignores the specified number of objects and then gets the remaining objects. Enter the number of objects to skip. + + Int32 + + Int32 + + + None + + + Paginate + + Whether or not you want to paginate through the results. + + Boolean + + Boolean + + + None + Get-JCAssociation @@ -2079,7 +2319,7 @@ False - + Name The name of the object. @@ -2091,7 +2331,7 @@ None - + TargetType The type of the target object. @@ -2138,6 +2378,66 @@ False + + Fields + + An array of the fields/properties/columns you want to return from the search. + + Array + + Array + + + None + + + Filter + + Filters to narrow down search. + + String + + String + + + None + + + Limit + + The number of items you want to return per API call. + + Int32 + + Int32 + + + None + + + Skip + + Ignores the specified number of objects and then gets the remaining objects. Enter the number of objects to skip. + + Int32 + + Int32 + + + None + + + Paginate + + Whether or not you want to paginate through the results. + + Boolean + + Boolean + + + None + @@ -2225,7 +2525,7 @@ False - + Name The name of the object. @@ -2237,7 +2537,7 @@ None - + TargetType The type of the target object. @@ -2261,9 +2561,69 @@ None - - - + + Fields + + An array of the fields/properties/columns you want to return from the search. + + Array + + Array + + + None + + + Filter + + Filters to narrow down search. + + String + + String + + + None + + + Limit + + The number of items you want to return per API call. + + Int32 + + Int32 + + + None + + + Skip + + Ignores the specified number of objects and then gets the remaining objects. Enter the number of objects to skip. + + Int32 + + Int32 + + + None + + + Paginate + + Whether or not you want to paginate through the results. + + Boolean + + Boolean + + + None + + + + System.String @@ -4147,6 +4507,17 @@ None + + SystemFDEKey + + A switch parameter to reveal the SystemFDEKey + + + SwitchParameter + + + False + Get-JCSystem @@ -4675,6 +5046,18 @@ None + + SystemFDEKey + + A switch parameter to reveal the SystemFDEKey + + SwitchParameter + + SwitchParameter + + + False + @@ -4816,7 +5199,316 @@ ByID - If searching for a System Group using the GroupID populate the GroupID in the -ByID field. + If searching for a System Group using the GroupID populate the GroupID in the -ByID field. + + String + + String + + + None + + + GroupName + + The name of the JumpCloud System Group you want to return the members of. + + String + + String + + + None + + + + + + System.String + + + + + + + + + + System.Object + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Get-JCSystemGroupMember -GroupName 'OSX Group' + + Returns the JumpCloud Systems that are a member of the group 'OSX Group' + + + + -------------------------- Example 2 -------------------------- + PS C:\> Get-JCGroup -Type System | Get-JCSystemGroupMember + + Returns all JumpCloud System Groups and their System members. + + + + -------------------------- Example 3 -------------------------- + PS C:\> Get-JCGroup -Type System | Get-JCSystemGroupMember | Where-Object System -EQ 'Server01' + + Returns all JumpCloud System Groups that the system with a hostname of 'Server01' is a member of. + + + + + + Online Version: + https://github.com/TheJumpCloud/support/wiki/Get-JCSystemGroupMember + + + + + + Get-JCSystemInsights + Get + JCSystemInsights + + JumpCloud's System Insights feature provides admins with the ability to easily interrogate their fleet of systems to find important pieces of information. Using this function you can easily gather heightened levels of information from your fleet of JumpCloud managed systems. + + + + Using Get-JCSystemInsights will allow you to easily query JumpCloud's RESTful API to return information from your fleet of JumpCloud managed systems. + + + + Get-JCSystemInsights + + Fields + + An array of the fields/properties/columns you want to return from the search. + + Array + + Array + + + None + + + Filter + + Filters to narrow down search. + + String + + String + + + None + + + Id + + The unique id of the object. + + String[] + + String[] + + + None + + + Limit + + The number of items you want to return per API call. + + Int32 + + Int32 + + + None + + + Skip + + Ignores the specified number of objects and then gets the remaining objects. Enter the number of objects to skip. + + Int32 + + Int32 + + + None + + + Table + + The SystemInsights table to query against. + + + apps + browser_plugins + chrome_extensions + disk_encryption + firefox_addons + groups + interface_addresses + mounts + os_version + safari_extensions + system_info + users + + String + + String + + + None + + + Paginate + + Whether or not you want to paginate through the results. + + Boolean + + Boolean + + + None + + + + Get-JCSystemInsights + + Fields + + An array of the fields/properties/columns you want to return from the search. + + Array + + Array + + + None + + + Filter + + Filters to narrow down search. + + String + + String + + + None + + + Limit + + The number of items you want to return per API call. + + Int32 + + Int32 + + + None + + + Name + + The name of the object. + + String[] + + String[] + + + None + + + Skip + + Ignores the specified number of objects and then gets the remaining objects. Enter the number of objects to skip. + + Int32 + + Int32 + + + None + + + Table + + The SystemInsights table to query against. + + + apps + browser_plugins + chrome_extensions + disk_encryption + firefox_addons + groups + interface_addresses + mounts + os_version + safari_extensions + system_info + users + + String + + String + + + None + + + Paginate + + Whether or not you want to paginate through the results. + + Boolean + + Boolean + + + None + + + + + + Fields + + An array of the fields/properties/columns you want to return from the search. + + Array + + Array + + + None + + + Filter + + Filters to narrow down search. String @@ -4825,10 +5517,58 @@ None - - GroupName + + Id - The name of the JumpCloud System Group you want to return the members of. + The unique id of the object. + + String[] + + String[] + + + None + + + Limit + + The number of items you want to return per API call. + + Int32 + + Int32 + + + None + + + Name + + The name of the object. + + String[] + + String[] + + + None + + + Skip + + Ignores the specified number of objects and then gets the remaining objects. Enter the number of objects to skip. + + Int32 + + Int32 + + + None + + + Table + + The SystemInsights table to query against. String @@ -4837,6 +5577,18 @@ None + + Paginate + + Whether or not you want to paginate through the results. + + Boolean + + Boolean + + + None + @@ -4847,6 +5599,30 @@ + + + System.Array + + + + + + + + System.String[] + + + + + + + + System.Int32 + + + + + @@ -4866,30 +5642,51 @@ -------------------------- Example 1 -------------------------- - PS C:\> Get-JCSystemGroupMember -GroupName 'OSX Group' + PS C:\> Get-JCSystemInsights -Table:('os_version'); - Returns the JumpCloud Systems that are a member of the group 'OSX Group' + Return os_version data for all systems that have system insights enabled. -------------------------- Example 2 -------------------------- - PS C:\> Get-JCGroup -Type System | Get-JCSystemGroupMember + PS C:\> Get-JCSystemInsights -Table:('os_version') -Id:('5d0917420905f70e36e3c0d3'); - Returns all JumpCloud System Groups and their System members. + Return os_version data for a system with a specified id. -------------------------- Example 3 -------------------------- - PS C:\> Get-JCGroup -Type System | Get-JCSystemGroupMember | Where-Object System -EQ 'Server01' + PS C:\> Get-JCSystemInsights -Table:('os_version') -Id:('5d0917420905f70e36e3c0d3', '5d0bc68b8e41442ccd10254a'); - Returns all JumpCloud System Groups that the system with a hostname of 'Server01' is a member of. + Return os_version data for systems with specific ids. + + + + -------------------------- Example 4 -------------------------- + PS C:\> Get-JCSystemInsights -Table:('os_version') -Name:('MacBook-Pro.local_TEST'); + + Return os_version data for a system with a specified name. + + + + -------------------------- Example 5 -------------------------- + PS C:\> Get-JCSystemInsights -Table:('os_version') -Name:('MacBook-Pro.local_TEST', 'Holly-Flax-Mac.local_TEST'); + + Return os_version data for systems with specific names. + + + + -------------------------- Example 6 -------------------------- + PS C:\> Get-JCSystemInsights -Table users -Filter username:eq:jcadmin + + Filters the users table for any system with the username jcadmin. Online Version: - https://github.com/TheJumpCloud/support/wiki/Get-JCSystemGroupMember + https://github.com/TheJumpCloud/support/wiki/Get-JCSystemInsights @@ -8591,7 +9388,7 @@ SystemID CommandID Status None - + TargetType The type of the target object. @@ -8616,6 +9413,66 @@ SystemID CommandID Status None + + Fields + + An array of the fields/properties/columns you want to return from the search. + + Array + + Array + + + None + + + Filter + + Filters to narrow down search. + + String + + String + + + None + + + Limit + + The number of items you want to return per API call. + + Int32 + + Int32 + + + None + + + Skip + + Ignores the specified number of objects and then gets the remaining objects. Enter the number of objects to skip. + + Int32 + + Int32 + + + None + + + Paginate + + Whether or not you want to paginate through the results. + + Boolean + + Boolean + + + None + Remove-JCAssociation @@ -8679,7 +9536,7 @@ SystemID CommandID Status False - + Name The name of the object. @@ -8691,7 +9548,7 @@ SystemID CommandID Status None - + TargetType The type of the target object. @@ -8716,6 +9573,66 @@ SystemID CommandID Status None + + Fields + + An array of the fields/properties/columns you want to return from the search. + + Array + + Array + + + None + + + Filter + + Filters to narrow down search. + + String + + String + + + None + + + Limit + + The number of items you want to return per API call. + + Int32 + + Int32 + + + None + + + Skip + + Ignores the specified number of objects and then gets the remaining objects. Enter the number of objects to skip. + + Int32 + + Int32 + + + None + + + Paginate + + Whether or not you want to paginate through the results. + + Boolean + + Boolean + + + None + @@ -8743,7 +9660,7 @@ SystemID CommandID Status None - + Name The name of the object. @@ -8779,7 +9696,7 @@ SystemID CommandID Status None - + TargetType The type of the target object. @@ -8803,6 +9720,66 @@ SystemID CommandID Status None + + Fields + + An array of the fields/properties/columns you want to return from the search. + + Array + + Array + + + None + + + Filter + + Filters to narrow down search. + + String + + String + + + None + + + Limit + + The number of items you want to return per API call. + + Int32 + + Int32 + + + None + + + Skip + + Ignores the specified number of objects and then gets the remaining objects. Enter the number of objects to skip. + + Int32 + + Int32 + + + None + + + Paginate + + Whether or not you want to paginate through the results. + + Boolean + + Boolean + + + None + diff --git a/PowerShell/ModuleBanner.md b/PowerShell/ModuleBanner.md index 40e987696..6267022f7 100755 --- a/PowerShell/ModuleBanner.md +++ b/PowerShell/ModuleBanner.md @@ -1,17 +1,17 @@ #### Latest Version ``` -1.12.1 +1.13.0 ``` #### Banner Current ``` -Module up-to-date. Add-JCAssociation and Remove-JCAssociation are now live! +Module up-to-date. Use Get-JCSystemInsights to query System Insights tables! ``` #### Banner Old ``` -JumpCloud module update available. Update now to use new functions Add-JCAssociation and Remove-JCAssociation! -``` \ No newline at end of file +Module update available! Query systemInsights tables and SystemFDEKeys! +``` diff --git a/PowerShell/ModuleChangelog.md b/PowerShell/ModuleChangelog.md index 3c79da70d..a0f4ac386 100644 --- a/PowerShell/ModuleChangelog.md +++ b/PowerShell/ModuleChangelog.md @@ -1,3 +1,33 @@ +## 1.13.0 + +Release Date: July 16, 2019 + +#### RELEASE NOTES + +``` +Changes for automating build and testing of module. +New function Get-JCSystemInsights. +Updated Function: Get-JCSystem with new parameter "-SystemFDEKey" +to return the SystemFDEKey. +``` + +#### FEATURES: + +- New Function: Use Get-JCSystemInsights to leverage the new EA system insights API endpoints. These endpoints allow admins to query additional system details for systems that are enabled for System Insights. [Find more information about System Insights here](https://jumpcloud-success.s3.amazonaws.com/resources/System+Insights+Early+Access.pdf) +- Updated Function: Get-JCSystem to allow for revealing the FileVault or BitLocker key. Use the "Switch" parameter "-SystemFDEKey" to display this key from the PowerShell terminal. +- Updated Function: Get-JCSystem "-returnProperties" parameter set to include "fde" and "systemInsights". + +#### IMPROVEMENTS: + +Remove dynamic validate set functionality for -Id and -Name parameters due to performance issues. +Updated test files to contain code within the describe blocks. +Renamed private function files to match the same name of the function within. +New Get-JCCommonParameters function. + +#### BUG FIXES: + +N/A + ## 1.12.1 Release Date: June 17, 2019