cDownloadFile.psm1

[DscResource()]
class cDownloadFile
{

    #This property is the url of the file to be downloaded
    [DscProperty(Key)]
    [string]$Url

    #This is the fully qualified path for the file that is expected to be 'Present' or 'Absent'
    [DscProperty(Mandatory)]
    [string]$DestinationPath

    [DscProperty()]
    [bool] $UpdateOnDiff = $true

    [void]Set()
    {
        write-verbose "Starting download from url: $($this.Url)"
        $client = New-Object System.Net.WebClient
        $client.DownloadFile($this.Url,$this.DestinationPath)
    }

    [bool]Test()
    {
        
        Write-Verbose "Checking if $($this.DestinationPath) exists"
        $file = Test-Path $this.DestinationPath

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

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

            if($ServerFileLenght -eq $file.Length){
                Write-Verbose 'File on server is identical to from existing file.'
                return $true
            }
        }
        Write-Verbose "New version of file not found!"
        return $false
    }

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

        return $returnValue
    }
}