DSCResources/src/cMonitorPerformanceCounter.0.1.resource.ps1

Write-DSCResource <#-ResourceName cMonitorPerformanceCounter -ModuleRoot $sysModules\cFg #>-Property @{
    CounterPath = 'The path to the performance counter'
    Value = 'The value of the performance counter', [Double]
    Timestamp = 'The timestamp', [DateTime]    
    CounterType = 'The type of performance counter'
} -Set {
    Get-Counter

    $DscDataClass  =
        Get-WmiObject -Namespace Root\Microsoft\Windows\DesiredStateConfiguration -List cMonitorPerformanceCounter 
    

    Get-Counter -Counter $counterPath |
        Select-Object -ExpandProperty CounterSamples | 
        ForEach-Object {
            $WmiInfo = $_ 
            $newInstance = $DscDataClass.CreateInstance()
            $newInstance.CounterPath = $WmiInfo.Path
            $newInstance.Value = $WmiInfo.CookedValue
            $newInstance.CounterType = $WmiInfo.CounterType            
            $newInstance.Timestamp = [Management.ManagementDateTimeConverter]::ToDmtfDateTime($wmiInfo.Timestamp)            
            $null = $newInstance.Put()
        }       
} -KeyProperty CounterPath, Timestamp