Functions/HealthCheck/Workflows/Get-AMHCInvalidWorkflowAgent.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function Get-AMHCInvalidWorkflowAgent {
    <#
        .SYNOPSIS
            Invalid Workflow Agent References
         
        .DESCRIPTION
            Workflows that have items that reference non-existent agents (can happen when an agent is removed/added during upgrade)
 
        .PARAMETER Workflows
            The workflows to perform health check against
 
        .PARAMETER AllAgents
            The agents and agent groups to perform the health check against
 
        .PARAMETER Repository
            The workflows, tasks, conditions and processes to perform health check against
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [AllowNull()]
        $Workflows,

        [Parameter(Mandatory = $true)]
        [AllowNull()]
        $AllAgents,

        [Parameter(Mandatory = $true)]
        [AllowNull()]
        $Repository
    )

    foreach ($workflow in $Workflows) {
        foreach ($trigger in $workflow.Triggers) {
            if ($trigger.AgentID -notin $AllAgents.ID -and $trigger.TriggerType -ne "Schedule") {
                $repoItem = $Repository | Where-Object {$_.ID -eq $trigger.ConstructID}
                [AMConstructHealthCheckItem]::New($workflow, "$($trigger.ConstructType): $($repoItem.Name)")
            }
        }
        foreach ($item in $workflow.Items) {
            if ($item.AgentID -notin $AllAgents.ID -and $item.ConstructType -notin "Workflow","Evaluation","Wait") {
                $repoItem = $Repository | Where-Object {$_.ID -eq $item.ConstructID}
                [AMConstructHealthCheckItem]::New($workflow, "$($item.ConstructType): $($repoItem.Name)")
            }
        }
    }
}