ScheduledTasks.ArgumentCompleters.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
#
# .SYNOPSIS
#
# Complete the -TaskName argument to ScheduledTask module cmdlets
#
function ScheduledTaskTaskNameArgumentCompletion
{
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)

    Get-ScheduledTask -TaskName "$wordToComplete*" |
        Sort-Object TaskName |
        ForEach-Object {
            New-CompletionResult $_.TaskName $_.Description
        }
}


#
# .SYNOPSIS
#
# Complete the -TaskPath argument to ScheduledTask module cmdlets
#
function ScheduledTaskTaskPathArgumentCompletion
{
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)

    Get-ScheduledTask -TaskPath "*$wordToComplete*" |
        Sort-Object TaskPath |
        ForEach-Object {
            New-CompletionResult $_.TaskPath $_.Description
        }
}


Register-ArgumentCompleter `
    -Command ('Disable-ScheduledTask','Enable-ScheduledTask','Export-ScheduledTask','Get-ClusteredScheduledTask','Get-ScheduledTask','Get-ScheduledTaskInfo','Register-ClusteredScheduledTask','Register-ScheduledTask','Set-ClusteredScheduledTask','Set-ScheduledTask','Start-ScheduledTask','Stop-ScheduledTask','Unregister-ClusteredScheduledTask','Unregister-ScheduledTask') `
    -Parameter 'TaskName' `
    -Description 'Complete task names' `
    -ScriptBlock $function:ScheduledTaskTaskNameArgumentCompletion


Register-ArgumentCompleter `
    -Command ('Disable-ScheduledTask','Enable-ScheduledTask','Export-ScheduledTask','Get-ScheduledTask','Get-ScheduledTaskInfo','Register-ScheduledTask','Set-ScheduledTask','Start-ScheduledTask','Stop-ScheduledTask','Unregister-ScheduledTask') `
    -Parameter 'TaskPath' `
    -Description 'Complete task path arguments for scheduled task cmdlets' `
    -ScriptBlock $function:ScheduledTaskTaskPathArgumentCompletion