DSCResources/cWmiIntervalTimer/cWmiIntervalTimer.psm1


function Get-TargetResource {
    [CmdletBinding()]
    [OutputType([Hashtable])]
    param([Parameter(Mandatory=$true)]
[uint64]
$IntervalBetweenEvents,
    [Parameter(Mandatory=$true)]
[string]
$TimerId)

    
    $existingTimer = Get-WmiObject -Namespace root\cimv2 -Class __IntervalTimerInstruction -Filter "TimerID = '$TimerID'"
    if (-not $existingTimer) { return @{} } 

    return @{
        TimerID = $existingTimer.TimerID
        SkipIfPassed = $existingTimer.SkipIfPassed
        IntervalBetweenEvents = $existingTimer.IntervalBetweenEvents
    }

}

function Set-TargetResource {
    [CmdletBinding()]
    
    param([Parameter(Mandatory=$true)]
[uint64]
$IntervalBetweenEvents,
    [Parameter()]
[bool]
$SkipIfPassed,
    [Parameter(Mandatory=$true)]
[string]
$TimerId)

    
    $wmiClass = [wmiclass]'__IntervalTimerInstruction'
    $newInstance = $wmiClass.CreateInstance()
    $newInstance.TimerID = $timerID
    $newInstance.IntervalBetweenEvents = $intervalBetweenEvents
    $newInstance.SkipIfPassed = $SkipIfPassed 
    $null = $newInstance.Put()    

}

function Test-TargetResource {
    [CmdletBinding()]
    [OutputType([bool])]
    param([Parameter(Mandatory=$true)]
[uint64]
$IntervalBetweenEvents,
    [Parameter()]
[bool]
$SkipIfPassed,
    [Parameter(Mandatory=$true)]
[string]
$TimerId)

    
    $existingTimer = Get-WmiObject -Namespace root\cimv2 -Class __IntervalTimerInstruction -Filter "TimerID = '$TimerID'"

    $existingTimer -and 
        $existingTimer.IntervalBetweenEvents -eq $IntervalBetweenEvents -and 
        $existingTimer.TimerID -eq $TimerID -and
        $existingTimer.SkipIfPassed -eq $SkipIfPassed

}

Export-ModuleMember -Function Get-TargetResource, Set-TargetResource, Test-TargetResource