Scripts/New-BPAObject.ps1

function New-BPAObject {
    <#
        .SYNOPSIS
            Creates an AutoMate BPA object.
 
        .DESCRIPTION
            New-BPAObject receives new BPA object(s) on the pipeline, or via the parameter $InputObject, and creates the objects.
 
        .PARAMETER InputObject
            The object(s) to be created.
 
        .INPUTS
            The following objects can be created by this function:
            Workflow
            Task
            Process
            TaskAgent
            ProcessAgent
            AgentGroup
            User
            UserGroup
 
        .NOTES
            Author(s): : David Seibel
            Contributor(s) :
            Date Created : 02/05/2018
            Date Modified : 02/06/2018
        .LINK
            https://github.com/davidseibel/PoshBPA
    #>

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

        [Parameter(Mandatory = $true)]
        $BPAServer
    )

    PROCESS {
        foreach ($obj in $InputObject) {
            $type = [BPAConstructType]$obj.Type
            $json = ConvertTo-BPAJson -InputObject $obj
            $splat = @{
                Resource = "$(([BPATypeDictionary]::($type)).RestResource)/create"
                RestMethod = "Post"
                Body = $json
                BPAServer = $BPAServer
            }
            Invoke-BPARestMethod @splat | Out-Null
            Write-Verbose "Created $($type): $(Join-Path -Path $obj.Path -ChildPath $obj.Name) on server $BPAServer."
        }
    }
}