DSCResources/cWmiAbsoluteTimer/cWmiAbsoluteTimer.psm1


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

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

    return @{
        TimerID = $existingTimer.TimerID
        SkipIfPassed = $existingTimer.SkipIfPassed
        EventDateTime = $existingTimer.ConvertToDateTime($existingTimer.EventDateTime)
    }

}

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

    
    $wmiClass = [wmiclass]'__AbsoluteTimerInstruction'
    $newInstance = $wmiClass.CreateInstance()
    $newInstance.TimerID = $timerID
    $newInstance.EventDateTime = $newInstance.ConvertFromDateTime($eventDateTime)
    $newInstance.SkipIfPassed = $skipIfPassed
    $null = $newInstance.Put()    

}

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

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

    $existingTimer -and 
        $existingTimer.EventDateTime -eq $existingTimer.ConvertFromDateTime($EventDateTime) -and 
        $existingTimer.TimerID -eq $TimerID -and
        $existingTimer.SkipIfPassed -eq $SkipIfPassed

}

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