functions/taskengine/Test-PSFTaskEngineTask.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
function Test-PSFTaskEngineTask
{
    <#
        .SYNOPSIS
            Tests, whether the specified task has already been executed.
         
        .DESCRIPTION
            Tests, whether the specified task has already been executed.
            Returns false, if the task doesn't exist.
         
        .PARAMETER Name
            Name of the task to test
         
        .EXAMPLE
            PS C:\> Test-PSFTaskEngineTask -Name 'mymodule.maintenance'
     
            Returns, whether the task named 'mymodule.maintenance' has already been executed at least once.
    #>

    [OutputType([System.Boolean])]
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true)]
        [string]
        $Name
    )
    
    if (-not ([PSFramework.TaskEngine.TaskHost]::Tasks.ContainsKey($Name.ToLower())))
    {
        return $false
    }
    
    $task = [PSFramework.TaskEngine.TaskHost]::Tasks[$Name.ToLower()]
    $task.LastExecution -gt $task.Registered
}