DSCResources/cMonitorDiskSpace/cMonitorDiskSpace.psm1


function Get-TargetResource {
    [CmdletBinding()]
    [OutputType([Hashtable])]
    param([Parameter(Mandatory=$true)]
[datetime]
$Timestamp,
    [Parameter(Mandatory=$true)]
[string]
$DeviceID)

    @{}
}

function Set-TargetResource {
    [CmdletBinding()]
    
    param([Parameter()]
[string]
$FileSystem,
    [Parameter()]
[string]
$VolumeName,
    [Parameter(Mandatory=$true)]
[datetime]
$Timestamp,
    [Parameter()]
[uint64]
$FreeSpace,
    [Parameter()]
[double]
$PercentFree,
    [Parameter(Mandatory=$true)]
[string]
$DeviceID,
    [Parameter()]
[uint64]
$Size)

    
    $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()
        }       

}

function Test-TargetResource {
    [CmdletBinding()]
    [OutputType([bool])]
    param([Parameter()]
[string]
$FileSystem,
    [Parameter()]
[string]
$VolumeName,
    [Parameter(Mandatory=$true)]
[datetime]
$Timestamp,
    [Parameter()]
[uint64]
$FreeSpace,
    [Parameter()]
[double]
$PercentFree,
    [Parameter(Mandatory=$true)]
[string]
$DeviceID,
    [Parameter()]
[uint64]
$Size)

    return $false
}

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