Scripts/Enable-BPAObject.ps1

function Enable-BPAObject {
    <#
        .SYNOPSIS
            Disables an AutoMate BPA object.
 
        .DESCRIPTION
            Disable-BPAObject receives BPA object(s) on the pipeline, or via the parameter $InputObject, and disables the object(s).
 
        .PARAMETER InputObject
            The object(s) to be disabled.
 
        .INPUTS
            The following objects can be disabled by this function:
            Workflow
            Task
            Condition
            Process
            TaskAgent
            ProcessAgent
            AgentGroup
            User
            UserGroup
 
        .EXAMPLE
            Get-BPAAgent "agent01" | Enable-BPAObject
 
        .NOTES
            Author(s): : David Seibel
            Contributor(s) :
            Date Created : 09/12/2016
            Date Modified : 05/01/2018
 
        .LINK
            https://github.com/davidseibel/PoshBPA
    #>

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

    PROCESS {
        # Loop through all objects on the pipeline
        foreach ($obj in $InputObject) {
            Write-Verbose "Processing object Name: '$($obj.Name)' Type: '$($obj.TypeName)'"
            if ($obj.TypeName -in @("Workflow","Task","Condition","Process","Agent","AgentGroup","User","UserGroup")) {
                # If object isn't already enabled, enable it
                if (-not $obj.Enabled) {
                    Write-Verbose "Enabling object '$($obj.Name) (Type: $($obj.TypeName))'."
                    Invoke-BPARestMethod -Resource "$([BPATypeDictionary]::($obj.TypeName).RestResource)/$($obj.ID)/enable" -RestMethod Post -BPAServer $obj.BPAServer | Out-Null
                } else {
                    Write-Verbose "Object '$($obj.Name)' already enabled."
                }
            } else {
                Write-Error -Message "Unsupported input type '$($obj.TypeName)' encountered!" -TargetObject $obj
            }
        }
    }
}