DSCResources/src/cMonitorDiskSpace.0.3.Resource.ps1

Write-DSCResource <#-ResourceName cMonitorDiskSpace -ModuleRoot $sysModules\cFg #>-Property @{
    FreeSpace = 'The amount of free space on the disk, in bytes', [Uint64]
    Size = 'The size of the disk, in bytes', [Uint64]
    VolumeName = 'The name of the volume'
    Timestamp = 'The timestamp', [DateTime]   
    FileSystem = 'The filesystem of the disk'
    PercentFree = 'The percentage of free disk space', [Double]
    DeviceID = 'The device ID'
} -Set {
    $DscDataClass  =
        Get-WmiObject -Namespace Root\Microsoft\Windows\DesiredStateConfiguration -List cMonitorDiskSpace

    Get-WmiObject Win32_LogicalDisk | 
        ForEach-Object {
            $WmiInfo = $_ 
            $newInstance = $DscDataClass.CreateInstance()
            $newInstance.FreeSpace = $WmiInfo.FreeSpace
            $newInstance.volumeName = $WmiInfo.VolumeName
            $newInstance.FileSystem = $WmiInfo.Filesystem
            $newInstance.DeviceID = $WmiInfo.DeviceID
            $newInstance.Size = $WmiInfo.Size 
            $newInstance.Timestamp = [Management.ManagementDateTimeConverter]::ToDmtfDateTime([Datetime]::Now)
            try {
                $newInstance.PercentFree = ($WmiInfo.FreeSpace / $WmiInfo.Size) * 100 
            } catch {

            }
            $null = $newInstance.Put()
        }       
} -KeyProperty DeviceID, Timestamp