$DNSHelper = $Global:ToolsDirectory + '\ekdns.exe' # SHA-256 of ekdns.exe from each v2.3.0 Windows release archive. If ([Environment]::Is64BitOperatingSystem) { $DNSHelperURL = 'https://xfer.emberkom.com/shares/tools/folders/9b9988fb-c53a-4833-a4ad-68d01a3021bb/files/ekdns-x64-exe/download/ekdns-x64.exe' $DNSHelperHash = '308E36680C0E4AD7CE802F4B1D8C38E89B0D8E24BBCE4F33550721C78BA2224C' } Else { $DNSHelperURL = 'https://xfer.emberkom.com/shares/tools/folders/9b9988fb-c53a-4833-a4ad-68d01a3021bb/files/ekdns-x86-exe/download/ekdns-x86.exe' $DNSHelperHash = 'F987E75D8FFB87B587B57D2394131B072957C0E3EB6B73B4FB784E9B0D65277B' } $InstalledHash = (Get-FileHash -LiteralPath $DNSHelper -Algorithm SHA256 -ErrorAction SilentlyContinue).Hash If ($InstalledHash -ne $DNSHelperHash) { $StagedHelper = $DNSHelper + '.' + [guid]::NewGuid().ToString('N') + '.tmp' Try { Write-Output "Downloading latest version of ekDNSHelper" $null = Download-File -URL $DNSHelperURL -File $StagedHelper If ((Get-FileHash -LiteralPath $StagedHelper -Algorithm SHA256 -ErrorAction Stop).Hash -ne $DNSHelperHash) { Throw 'Downloaded ekdns.exe failed SHA-256 verification.' } If ([IO.File]::Exists($DNSHelper)) { [IO.File]::Replace($StagedHelper, $DNSHelper, [NullString]::Value) } Else { [IO.File]::Move($StagedHelper, $DNSHelper) } } Catch { Write-Error $_.Exception.Message Exit 1 } Finally { Remove-Item -LiteralPath $StagedHelper -Force -ErrorAction SilentlyContinue } } # Delete the old version of ekDNSHelper if it exists If ( Test-Path ($Global:ToolsDirectory + '\dnshelper.exe') ) { Write-Output "Deleting old version of ekDNSHelper: ${Global:ToolsDirectory}\dnshelper.exe" Remove-Item -Path ($Global:ToolsDirectory + '\dnshelper.exe') -Force -ErrorAction SilentlyContinue } $RefreshScript = $Global:ToolsDirectory + '\refresh-local-hosts.bat' $todaysDate = Get-LongDate $RefreshScriptHeader = @" @echo off REM Refresh IP to name mappings in local hosts file REM This script was created by an automatic process and should not be edited manually REM Author: David Yoder, Emberkom LLC (Fix-UpdateLocalHosts.ps1) REM Updated: ${todaysDate}`n "@ $Hosts = @( 'auth.services.mspbackups.com', 'ws.mspbackups.com' ) If ($BackupBucket.Length -ge 2 ) { $Hosts += $BackupBucket } $HostString = '' ForEach ($Hostname in $Hosts) { If ($HostString.Length -gt 0) { $HostString = $HostString + ',' + $Hostname } Else { $HostString = $Hostname } } If ( Test-Path $DNSHelper ) { $commandString = """${DNSHelper}"" add -host ${HostString}" $content = $RefreshScriptHeader + $commandString Write-Output "Creating latest refresh script" Try { Set-Content -LiteralPath $RefreshScript -Value $content -Force -ErrorAction Stop Write-Output "Updating local hosts file with name-to-IP mappings for the following host(s): ${HostString}" & "${RefreshScript}" If ($LASTEXITCODE -ne 0) { Exit $LASTEXITCODE } } Catch { Write-Error $_.Exception.Message ; Exit 1 } } Else { Write-Error "Cannot find the DNS Helper executable: ""${DNSHelper}""" Exit 1 }