PSTimers.psm1

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

#TODO: Add a WPF timer

#dot source file with function definitions
. $PSScriptRoot\PSTimerFunctions.ps1

#add autocompleter for MyTimer functions
$cmds = "Get-MyTimer","Set-MyTimer","Remove-MyTimer"
Register-ArgumentCompleter -CommandName $cmds -ParameterName Name -ScriptBlock {
    param($commandName, $parameterName, $wordToComplete="*", $commandAst, $fakeBoundParameter)

    $global:myTimerCollection.keys | 
    where-object {$_ -match $wordToComplete } |
    Sort-Object |
        ForEach-Object {
            [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue',$_)
        }
}

Register-ArgumentCompleter -CommandName Stop-Mytimer -ParameterName Name -ScriptBlock {
    param($commandName, $parameterName, $wordToComplete="*", $commandAst, $fakeBoundParameter)
    
    $global:myTimerCollection.values.where({$_.running}) | 
    where-object {$_ -match $wordToComplete } |
    Sort-Object -Property Name | 
        ForEach-Object {
            [System.Management.Automation.CompletionResult]::new($_.name, $_.name, 'ParameterValue',$_.name)
        }
}