Public/Search/Remove-JIMPredefinedSearchCriteriaGroup.ps1
|
# Copyright (c) Tetron Limited. All rights reserved. # Licensed under the Tetron Commercial License. See LICENSE file in the project root. function Remove-JIMPredefinedSearchCriteriaGroup { <# .SYNOPSIS Removes a criteria group (and its contents) from a Predefined Search. .DESCRIPTION Deletes a criteria group and its entire subtree (nested groups and all contained criteria) from a Predefined Search. .PARAMETER PredefinedSearchId The ID of the Predefined Search. .PARAMETER GroupId The ID of the criteria group to remove, with everything in it. .PARAMETER ChangeReason Why the group was removed, recorded on the audit Activity and shown in the Predefined Search's Configuration Change History. .OUTPUTS None. .EXAMPLE Remove-JIMPredefinedSearchCriteriaGroup -PredefinedSearchId 3 -GroupId 10 Removes criteria group 10 and everything within it. .EXAMPLE Remove-JIMPredefinedSearchCriteriaGroup -PredefinedSearchId 3 -GroupId 10 -ChangeReason "Consolidating filters (CHG0129)" Removes the group and records the reason on its Configuration Change History. .LINK Get-JIMPredefinedSearchCriteriaGroup New-JIMPredefinedSearchCriteriaGroup #> [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] [OutputType([void])] param( [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [int]$PredefinedSearchId, [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [Alias('Id')] [int]$GroupId, [ValidateNotNullOrEmpty()] [string]$ChangeReason ) process { if (-not $script:JIMConnection) { Write-Error "You are not connected to JIM. Run Connect-JIM -Url <your JIM URL> to authenticate, then try again." return } if ($PSCmdlet.ShouldProcess("Criteria Group $GroupId on Predefined Search $PredefinedSearchId", "Remove")) { Write-Verbose "Removing criteria group $GroupId from Predefined Search $PredefinedSearchId" try { $endpoint = "/api/v1/predefined-searches/$PredefinedSearchId/criteria-groups/$GroupId" if ($ChangeReason) { $endpoint += "?changeReason=$([uri]::EscapeDataString($ChangeReason))" } Invoke-JIMApi -Endpoint $endpoint -Method 'DELETE' Write-Verbose "Removed criteria group $GroupId" } catch { Write-Error "Failed to remove criteria group: $_" } } } } |