cDownloadFile.psm1

enum Ensure
{
    Absent
    Present
}

[DscResource()]
class cDownloadFile
{
    [DscProperty(Key)]
    [string]$Url

    [DscProperty(Mandatory)]
    [string]$DestinationPath

    [DscProperty(Mandatory)]
    [Ensure] $Ensure

    [DscProperty()]
    [bool] $UpdateOnDiff

    [void]Set()
    {
        if($this.Ensure -eq [Ensure]::Present)
        {
            write-verbose "Starting file download"
            $client = New-Object System.Net.WebClient
            $client.DownloadFile($this.Url,$this.DestinationPath)
        }else{
            write-verbose "Removing file..."
            Remove-Item $this.DestinationPath
        }
    }

    [bool]Test()
    {
        
        $fileThere = $false
        if($this.Ensure -eq [Ensure]::Present)
        {
            write-verbose "You want this file to be there!"
            $fileThere = -not $filethere
        }
        Write-Verbose "Checking if $($this.DestinationPath) exists"
        $file = Test-Path $this.DestinationPath

        if($file){
            Write-Verbose "File Exists"
            if(!$this.UpdateOnDiff){
                return $fileThere
            }

            $client = New-Object System.Net.WebClient
            $client.OpenRead($this.Url)|Out-Null
            $ServerFileLenght = $client.ResponseHeaders['Content-Lenght']

            if($ServerFileLenght -eq $file.Length){
                return $fileThere
            }
        }
        Write-Verbose "New version of file not found!"
        return -not $fileThere
    }

    [cDownloadFile]Get()
    {
        $returnValue = @{
            Url = [System.String]
            DestinationPath = [System.String]
            UpdateOnDiff = [System.Boolean]
            Ensure = [System.String]
        }

        return $returnValue
    }
}