Functions/HealthCheck/Workflows/Get-AMHCDisconnectedWorkflowItem.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
function Get-AMHCDisconnectedWorkflowItem {
    <#
        .SYNOPSIS
            Disconnected Workflow Items
 
        .DESCRIPTION
            Workflow items that don't have any connected links
 
        .PARAMETER Workflows
            The workflows to perform health check against
 
        .PARAMETER Repository
            The workflows, tasks, conditions and processes to perform health check against
    #>

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

        $Repository
    )

    foreach ($workflow in $Workflows) {
        $allItems = @($workflow.Triggers) + @($workflow.Items)
        if (($allItems | Measure-Object).Count -gt 1) {
            foreach ($trigger in $workflow.Triggers) {
                if ($workflow.Links.SourceID -notcontains $trigger.ID -and `
                    $workflow.Links.DestinationID -notcontains $trigger.ID) {
                    $repoItem = $Repository | Where-Object {$_.ID -eq $trigger.ConstructID}
                    [AMConstructHealthCheckItem]::New($workflow, "$($trigger.TriggerType): $($repoItem.Name)")
                }
            }
            foreach ($item in $workflow.Items) {
                if ($workflow.Links.SourceID -notcontains $item.ID -and `
                    $workflow.Links.DestinationID -notcontains $item.ID) {
                    $repoItem = $Repository | Where-Object {$_.ID -eq $item.ConstructID}
                    [AMConstructHealthCheckItem]::New($workflow, "$($item.ConstructType): $($repoItem.Name)")
                }
            }
        }
    }
}