Scripts/Add-BPASnmpConditionCredential.ps1

function Add-BPASnmpConditionCredential {    
    <#
        .SYNOPSIS
            Adds a credential to an AutoMate BPA SNMP condition.
 
        .DESCRIPTION
            Add-BPASnmpConditionCredential adds a credential to an AutoMate BPA SNMP condition.
 
        .PARAMETER InputObject
            The SNMP condition object to add the credential to.
 
        .PARAMETER User
            The username used to accept authenticated traps.
 
        .PARAMETER AuthenticationPassword
            The password for the specified user.
 
        .PARAMETER EncryptionAlgorithm
            The type encryption to use.
 
        .PARAMETER PrivacyPassword
            The encryption password.
 
        .EXAMPLE
            Get-BPACondition "snmp" | Add-BPASnmpConditionCredential -User david
 
        .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,
        
        $User,
        #$AuthenticationPassword,
        [BPAEncryptionAlgorithm]$EncryptionAlgorithm = [BPAEncryptionAlgorithm]::NoEncryption
        #$PrivacyPassword
    )

    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
                $credential = Get-BPAObjectTemplate -Type SNMPCredential -BPAServer $obj.BPAServer
                $credential.ID = "{$((New-Guid).Guid)}"
                if ($PSBoundParameters.ContainsKey("User")) {
                    $credential.User = $User
                }
                <#if ($PSBoundParameters.ContainsKey("AuthenticationPassword")) {
                    $credential.AuthenticationPassword = $AuthenticationPassword
                }#>

                if ($PSBoundParameters.ContainsKey("EncryptionAlgorithm")) {
                    $credential.EncryptionAlgorithm = $EncryptionAlgorithm.value__
                }
                <#if ($PSBoundParameters.ContainsKey("PrivacyPassword")) {
                    $credential.PrivacyPassword = $PrivacyPassword
                }#>

                $updateObject.Credentials += $credential
                $updateObject | Set-BPAObject
            } else {
                Write-Error -Message "Unsupported input type '$($obj.TypeName)' and trigger type '$($obj.TriggerType -as [BPATriggerType])' encountered!" -TargetObject $obj
            }
        }
    }
}