Get-DSCData.ps1

function Get-DSCData
{
    <#
    .Synopsis
        Gets data generated by a DSC resource
    .Description
        Gets data that was generated by a DSC resource.
    .Example
        Get-DSCData
    .Example
        Get-DSCData -ResourceName "MonitorDiskSpace"
    .Link
        Clear-DSCData
    #>

    [CmdletBinding(DefaultParameterSetName='AllDSCData')]
    [OutputType([PSObject])]
    param(
    # The name of the DSC resource.
    [Parameter(Mandatory=$true,
        Position=0,
        ParameterSetName='SpecificDSCData',
        ValueFromPipelineByPropertyName=$true)]
    [string]
    $ResourceName,

    # The name of the computer
    [string]
    $ComputerName,

    # The credential used to connect to the remote computer.
    [Management.Automation.PSCredential]
    $Credential,

    # If set, raw WMI data will be returned. Raw data will include many empty additional properties, and will return datetimes in DMTF format.
    [Switch]
    $Raw
    )

    process {
        if ($PSCmdlet.ParameterSetName -eq 'AllDscData') {
            #region Find each class and call Get-DSCData
            $splat = @{} + $PSBoundParameters
            $splat.Remove('Raw')
            $classList = Get-WmiObject -Namespace root\Microsoft\Windows\DesiredStateConfiguration -Query "Select * From META_CLASS where __This ISA 'OMI_BaseResource'" -ErrorAction SilentlyContinue @splat

            foreach ($class in $classList) {
                if ('OMI_BaseResource', 
                    'MSFT_DSCResource', 
                    'MSFT_ResourceNotInDesiredState', 
                    'MSFT_ResourceInDesiredState', 
                    'MSFT_FileDirectoryConfiguration' -contains $class.Name) {
                    continue
                }
                $PSBoundParameters['ResourceName'] = $class.Name
                Get-DSCData @PSBoundParameters
            }            
            #endregion Find each class and call Get-DSCData
        } elseif ($PSCmdlet.ParameterSetName -eq 'SpecificDSCData') {
            $WmiParams = @{
                Namespace = 'root\Microsoft\Windows\DesiredStateConfiguration'
                Class = $ResourceName
                ErrorAction = 'SilentlyContinue'
                Amended = $true
            }

            if ($ComputerName) {
                $WmiParams += @{ComputerName = $ComputerName} 
            }
            if ($Credential) {
                $WmiParams += @{Credential = $Credential}
            }
            if ($Raw) {                    
                Get-WmiObject @WmiParams
            } else {
                $AllWmiData = Get-WmiObject @WmiParams 
                
                foreach ($wmiData in $AllWmiData) {                                        
                    $propObject= New-Object PSObject
                    
                    foreach ($prop in $wmiData.psobject.properties) {
                        $null = $null
                        if ($prop.Name.StartsWith("__")) { continue } 
                        if ('ConfigurationName','Dependson', 
                            'ModuleName', 'ModuleVersion',
                            'PSDscRunAsCredential',
                            'SourceInfo'-contains $prop.Name) {
                            continue
                        }
                        if ('Scope', 'Path', 
                            'ClassPath', 'Options', 
                            'Qualifiers', 'Site', 
                            'Container', 'Properties', 'SystemProperties' -contains $prop.Name) { continue } 
                        $k = $prop.Name
                        $v = $prop.Value
                        if ($wmiData.Properties[$k] -and $wmiData.Properties[$k].Qualifiers['CimType'].Value -eq 'DateTime') {
                            $v = [Management.ManagementDateTimeConverter]::ToDateTime($v)
                        }
                            
                        $null = $propObject.psobject.properties.add((
                            New-Object Management.Automation.PSNoteProperty $k, $v 
                        ))
                                
                            
                    }   
                    $propObject.pstypenames.clear()
                    $propObject.pstypenames.add("$ResourceName.DSC.Data")
                    $propObject
                }
            }
        }
    }
}