Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
$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."
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
$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