Scripts/Get-BPASystemAgent.ps1
function Get-BPASystemAgent { <# .SYNOPSIS Gets AutoMate BPA system agent types. .DESCRIPTION Get-BPASystemAgent returns a list of system agent types and their IDs. .PARAMETER Type The type of system agent to return. .EXAMPLE # Get the default system agent Get-BPASystemAgent -Type Default .EXAMPLE # Get workflows that use "Previous Agent" Get-BPASystemAgent -Type Previous | Get-BPAWorkflow .NOTES Author(s): : David Seibel Contributor(s) : Date Created : 10/26/2016 Date Modified : 04/12/2018 .LINK https://github.com/davidseibel/PoshBPA #> [CmdletBinding(DefaultParameterSetName="All")] [OutputType([System.Object[]])] param( [Parameter(ParameterSetName="ByID")] [ValidateNotNullOrEmpty()] [string]$ID, [Parameter(ParameterSetName="ByType")] [ValidateSet("Condition","Default","Previous","Triggered","Variable")] [string]$Type, [string]$BPAServer ) if ($BPAServer) { if ($BPAServer -notin $BPAConnectionInfo.Server) { throw "Not connected to server $BPAServer!" } $servers = @($BPAServer) } else { $servers = @($global:BPAConnectionInfo.Server) } foreach ($server in $servers) { switch ($PSCmdlet.ParameterSetName) { "ByID" { $name = [BPASystemAgent]::new().GetByID($ID) if ($name) { [PSCustomObject]@{ ID = $ID Name = $name TypeName = "SystemAgent" BPAServer = $server } } } "ByType" { # Return specified system agent type [PSCustomObject]@{ ID = [BPASystemAgent]::$Type Name = $Type TypeName = "SystemAgent" BPAServer = $server } } "All" { # Return all system agent types $Types = @("Condition","Default","Previous","Triggered","Variable") foreach ($Type in $Types) { [PSCustomObject]@{ ID = [BPASystemAgent]::$Type Name = $Type TypeName = "SystemAgent" BPAServer = $server } } } } } } |