functions/domain-index/Remove-TssDomainIndex.ps1

function Remove-TssDomainIndex {
    <#
    .SYNOPSIS
    Delete a domain name index entry
 
    .DESCRIPTION
    Delete one or more entries from the Discovery domain name index. Returns True per entry; the server also returns True for an ID that does not exist.
    The domain name index is the Discovery cache of domain names and the discovery source each one resolves to.
 
    .PARAMETER TssSession
    TssSession object created by New-TssSession for authentication
 
    .PARAMETER Id
    Domain name index entry ID
 
    .EXAMPLE
    $session = New-TssSession -SecretServer https://alpha -Credential $ssCred
    Remove-TssDomainIndex -TssSession $session -Id 12
 
    Delete entry 12
 
    .EXAMPLE
    $session = New-TssSession -SecretServer https://alpha -Credential $ssCred
    Search-TssDomainIndex -TssSession $session -DomainName old.example.com | Remove-TssDomainIndex -TssSession $session
 
    Delete the entries for a retired domain
 
    .LINK
    https://thycotic-ps.github.io/thycotic.secretserver/commands/domain-index/Remove-TssDomainIndex
 
    .LINK
    https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/domain-index/Remove-TssDomainIndex.ps1
 
    .NOTES
    Requires TssSession object returned by New-TssSession
    #>

    [CmdletBinding(SupportsShouldProcess)]
    [OutputType('System.Boolean')]
    param (
        [Parameter(Mandatory, ValueFromPipeline, Position = 0)]
        [Thycotic.PowerShell.Authentication.Session]
        $TssSession,

        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [Alias('DomainNameIndexId')]
        [int[]]
        $Id
    )
    begin {
        $tssParams = $PSBoundParameters
        $invokeParams = . $GetInvokeApiParams $TssSession
    }
    process {
        Get-TssInvocation $PSCmdlet.MyInvocation
        if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
            Compare-TssVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation
            foreach ($currentId in $Id) {
                $restResponse = $null
                $uri = $TssSession.ApiUrl, 'domain-index', 'delete', $currentId -join '/'
                $invokeParams.Uri = $uri
                $invokeParams.Method = 'PUT'
                if ($PSCmdlet.ShouldProcess("Domain index: $currentId", "$($invokeParams.Method) $uri")) {
                    Write-Verbose "Performing the operation $($invokeParams.Method) $uri"
                    try {
                        $apiResponse = Invoke-TssApi @invokeParams
                        $restResponse = . $ProcessResponse $apiResponse
                    } catch {
                        Write-Warning 'Issue with Remove-TssDomainIndex request'
                        $err = $_
                        . $ErrorHandling $err
                    }
                    if ($null -ne $restResponse) {
[System.Convert]::ToBoolean($restResponse)
                    }
                }
            }
        } else {
            Write-Warning 'No valid session found'
        }
    }
}