Scripts/Set-BPAObject.ps1

function Set-BPAObject {
    <#
        .SYNOPSIS
            Modifies an AutoMate BPA object.
 
        .DESCRIPTION
            Set-BPAObject receives modified BPA object(s) on the pipeline, or via the parameter $InputObject, and applies the modifications.
 
        .PARAMETER InputObject
            The object(s) to be modified.
 
        .INPUTS
            The following objects can be modified by this function:
            Workflow
            Task
            Process
            TaskAgent
            ProcessAgent
            AgentGroup
            User
            UserGroup
 
        .EXAMPLE
            $obj = Get-BPAWorkflow "My Workflow"
            $obj.Notes = "New Notes"
            $obj | Set-BPAObject
 
        .NOTES
            Author(s): : David Seibel
            Contributor(s) :
            Date Created : 02/05/2018
            Date Modified : 02/23/2018
 
        .LINK
            https://github.com/davidseibel/PoshBPA
    #>

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

    PROCESS {
        foreach ($obj in $InputObject) {
            # Make sure the object is of the right type. If the original object was returned by the <construct>/list method, it is probably of the wrong type.
            if ($obj.TypeName -eq "Condition") {
                $obj.___type = Get-BPAObjectType -ConditionType $obj.TriggerType -BPAServer $obj.BPAServer                
            } else {
                $obj.___type = Get-BPAObjectType -Type $obj.Type -BPAServer $obj.BPAServer
            }
            $server = $obj.BPAServer
            $type = $obj.TypeName
            $json = ConvertTo-BPAJson -InputObject $obj
            $splat = @{
                Resource = "$(([BPATypeDictionary]::($type)).RestResource)/$($obj.ID)/update"
                RestMethod = "Post"
                Body = $json
                BPAServer = $server
            }
            if ($PSCmdlet.ShouldProcess($server, "Modifying $($type): $(Join-Path -Path $obj.Path -ChildPath $obj.Name)")) {
                Invoke-BPARestMethod @splat | Out-Null
                Write-Verbose "Modified $($type): $(Join-Path -Path $obj.Path -ChildPath $obj.Name)."
            }
        }
    }
}