functions/taskengine/Disable-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
35
36
function Disable-PSFTaskEngineTask
{
    <#
  .SYNOPSIS
   Disables a task registered to the PSFramework task engine.
   
  .DESCRIPTION
   Disables a task registered to the PSFramework task engine.
   
  .PARAMETER Task
   The task registered. Must be a task object returned by Get-PSFTaskEngineTask.
   
  .EXAMPLE
   PS C:\> Get-PSFTaskEngineTask -Name 'mymodule.maintenance' | Disable-PSFTaskEngineTask
  
   Disables the task named 'mymodule.maintenance'
 #>

    [CmdletBinding()]
    Param (
        [Parameter(ValueFromPipeline = $true, Mandatory = $true)]
        [PSFramework.TaskEngine.PsfTask[]]
        $Task
    )
    
    process
    {
        foreach ($item in $Task)
        {
            if ($item.Enabled)
            {
                Write-PSFMessage -Level Verbose -Message "Disabling task engine task: $($item.Name)" -Tag 'disable', 'taskengine', 'task'
                $item.Enabled = $false
            }
        }
    }
}