Scripts/Disable-BPAObject.ps1
function Disable-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-BPAWorkflow "My Workflow" | Disable-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 -notin @("Workflow","Task","Condition","Process","Agent","AgentGroup","User","UserGroup")) { Write-Error -Message "Unsupported input type '$($obj.TypeName)' encountered!" -TargetObject $obj } # If object isn't already disabled, disable it if ($obj.Enabled) { Write-Verbose "Disabling object '$($obj.Name) (Type: $($obj.TypeName))'." Invoke-BPARestMethod -Resource "$([BPATypeDictionary]::($obj.TypeName).RestResource)/$($obj.ID)/disable" -RestMethod Post -BPAServer $obj.BPAServer | Out-Null } else { Write-Verbose "Object '$($obj.Name)' already disabled." } } } } |