From 98c1b3e214afa57f3b77f420f8b8dd391340d764 Mon Sep 17 00:00:00 2001 From: David Yoder Date: Mon, 1 Jul 2024 11:19:20 -0400 Subject: [PATCH] create script and run that instead --- Fix-UpdateLocalHosts.ps1 | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Fix-UpdateLocalHosts.ps1 b/Fix-UpdateLocalHosts.ps1 index 37ed6e9..a756baa 100644 --- a/Fix-UpdateLocalHosts.ps1 +++ b/Fix-UpdateLocalHosts.ps1 @@ -3,6 +3,14 @@ $DNSHelper = $Global:ToolsDirectory + '\dnshelper.exe' If ( !(Test-Path $DNSHelper) ) { Download-File -URL $DNSHelperURL -File $DNSHelper } +$RefreshScript = $Global:ToolsDirectory + '\refresh-local-hosts.bat' +$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 +REM Updated: ${(Get-LongDate)} +"@ $Resolvers = @( '1.1.1.1', @@ -33,8 +41,18 @@ ForEach ($Hostname in $Hosts) { } If ( Test-Path $DNSHelper ) { + $commandString = """${DNSHelper}"" add -host ${HostString} -server ${ResolverString}" + $content = $RefreshScriptHeader + $commandString + Write-Output "Creating latest refresh script" + If ( Test-Path $RefreshScript ) { Remove-Item -Path $RefreshScript -Force } + Try { + New-Item -Path $RefreshScript -ItemType File -Force | Out-Null + Set-Content -Path $RefreshScript -Value $content + } + Catch { Write-Error $_.Exception.Message } + Write-Output "Updating local hosts file with name-to-IP mappings for the following host(s): ${HostString}" - & $DNSHelper add -host $HostString -server $ResolverString + & "${RefreshScript}" } Else { Write-Error "Cannot find the DNS Helper executable: ""${DNSHelper}""" }