Skip to content

Instantly share code, notes, and snippets.

@dvlin
Created May 8, 2015 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvlin/6f5da5f3c0f39a23d440 to your computer and use it in GitHub Desktop.
Save dvlin/6f5da5f3c0f39a23d440 to your computer and use it in GitHub Desktop.
$sourcepath = 'https://installer.msi'
$destinationpath = "C:temppath"
$filename = "installer.msi"
$registry = "hklm:softwareapplicationname"
$logname = "eventlogname"
$logsource = "eventlogsource"
if (-not (Get-EventLog -list | Where-Object {$_.logdisplayname -eq $logname})) {
New-EventLog -LogName $logname -Source $logsource
}
$wp = New-Object Security.Principal.WindowsPrincipal([System.Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $wp.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) {
Write-Eventlog -Logname $logname -Source $logsource -EventID 1000 -EntryType Error -Message "File downloader-script requires administrative privileges, please re-launch with elevated credentials."
#exit
}
if (-not (test-path($destinationpath))){
New-Item -ItemType Directory -Force -Path ($destinationpath)
}
if (-not (test-path($registry))){
New-Item -Path hklm:software -Name applicationname
}
if((Get-ItemProperty $registry -Name "etag" -ErrorAction 0).etag) {
$etag = (Get-Itemproperty $registry -Name "etag").etag
}else{
$etag = "0x0x0"
Set-ItemProperty -Path $registry -Name "etag" -Value $etag
}
try {
$abb = Invoke-WebRequest -Uri $sourcepath -Headers @{"If-None-Match"=$etag}
[io.file]::WriteAllBytes(($destinationpath+$filename), $abb.Content)
$etag = $abb.headers.etag
Set-ItemProperty -Path $registry -Name etag -Value $etag
}
catch {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment