Scripts/Remove-BPASnmpConditionCredential.ps1

function Remove-BPASnmpConditionCredential {    
    <#
        .SYNOPSIS
            Removes a credential from an AutoMate BPA SNMP condition.
 
        .DESCRIPTION
            Remove-BPASnmpConditionCredential removes a credential from an AutoMate BPA SNMP condition.
 
        .PARAMETER InputObject
            The SNMP condition object to remove the control from.
 
        .PARAMETER ID
            The ID of the credential.
 
        .EXAMPLE
            Get-BPACondition "snmp" | Remove-BPASnmpConditionCredential -ID "{5ccaab49-012a-48db-b186-696061e20a2c}"
 
        .NOTES
            Author(s): : David Seibel
            Contributor(s) :
            Date Created : 02/23/2018
            Date Modified : 02/23/2018
 
        .LINK
            https://github.com/davidseibel/PoshBPA
    #>

    [CmdletBinding(DefaultParameterSetName = "Default")]
    param(
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        $InputObject,
        
        [Parameter(Mandatory = $true)]
        $ID
    )

    PROCESS {
        foreach ($obj in $InputObject) {
            if (($obj.TypeName -eq "Condition") -and ($obj.TriggerType -eq [BPATriggerType]::SNMPTrap.value__)) {
                $updateObject = Get-BPACondition -ID $obj.ID -BPAServer $obj.BPAServer
                if ((($updateObject.Credentials | Where-Object {$_.ID -ne $ID}) | Measure-Object).Count -gt 0) {
                    $updateObject.Credentials = @($updateObject.Credentials | Where-Object {$_.ID -ne $ID})
                } else {
                    $updateObject.Credentials = @()
                }
                $updateObject | Set-BPAObject
            } else {
                Write-Error -Message "Unsupported input type '$($obj.TypeName)' and trigger type '$($obj.TriggerType -as [BPATriggerType])' encountered!" -TargetObject $obj
            }
        }
    }
}