Functions/HealthCheck/Tasks/Get-AMHCTaskVersionOld.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
function Get-AMHCTaskVersionOld {
    <#
        .SYNOPSIS
            Old Task Versions
 
        .DESCRIPTION
            Tasks whose version doesn't match the server version
 
        .PARAMETER Tasks
            The tasks to perform health check against
    #>

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

    foreach ($task in ($Tasks | Where-Object {-not [string]::IsNullOrEmpty($_.AML)})) {
        try {
            $xml = [xml]$task.AML
        } catch {
            # Old Task Version health check will report this
            continue
        }
        $taskConnection = Get-AMConnection -Connection $task.ConnectionAlias
        switch ($taskConnection.Version.Major) {
            10 {$taskVersion = $xml.AMTASK.AMTASKHEAD.TASKINFO.TASKVERSION}
            11 {$taskVersion = $xml.AutomateTask.TaskInfo.Version.TaskVersion}
        }
        if ([Version]$taskVersion -ne $taskConnection.Version) {
            [AMConstructHealthCheckItem]::New($task, "Task version: $taskVersion")
        }
    }
}