Scripts/Set-BPAAgent.ps1

function Set-BPAAgent {
    <#
        .SYNOPSIS
            Sets properties of an AutoMate BPA agent.
 
        .DESCRIPTION
            Set-BPAAgent can change properties of an agent object.
 
        .PARAMETER InputObject
            The object to modify.
 
        .PARAMETER Notes
            The new notes to set on the object.
 
        .INPUTS
            The following BPA object types can be modified by this function:
            TaskAgent
            ProcessAgent
 
        .EXAMPLE
            # Change notes for an agent
            Get-BPAAgent "Agent1" | Set-BPAAgent -Notes "Site 1 Agent"
 
        .NOTES
            Author(s): : David Seibel
            Contributor(s) :
            Date Created : 11/07/2016
            Date Modified : 05/01/2018
 
        .LINK
            https://github.com/davidseibel/PoshBPA
    #>

    [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='Medium')]
    param(
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        $InputObject,

        [Parameter(Mandatory = $true)]
        [AllowEmptyString()]
        [string]$Notes
    )
    PROCESS {
        foreach ($obj in $InputObject) {
            if ($obj.TypeName -eq "Agent") {
                $updateObject = Get-BPAAgent -ID $obj.ID -BPAServer $obj.BPAServer
                $shouldUpdate = $false
                if ($PSBoundParameters.ContainsKey("Notes")) {
                    if ($updateObject.Notes -ne $Notes) {
                        $updateObject.Notes = $Notes
                        $shouldUpdate = $true
                    }
                }
                if ($shouldUpdate) {
                    $updateObject | Set-BPAObject
                } else {
                    Write-Verbose "$($obj.TypeName) '$($obj.Name)' already contains the specified values."
                }
            } else {
                Write-Error -Message "Unsupported input type '$($obj.TypeName)' encountered!" -TargetObject $obj
            }
        }
    }
}