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() { $fileThere = $true 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 } } |