Files
management-scripts/Fix-UpdateLocalHosts.ps1
T

60 lines
1.8 KiB
PowerShell
Raw Normal View History

2024-06-07 14:30:07 -04:00
$DNSHelperURL = 'https://www.emberkom.com/tools/dnshelper.exe'
$DNSHelper = $Global:ToolsDirectory + '\dnshelper.exe'
If ( !(Test-Path $DNSHelper) ) {
Download-File -URL $DNSHelperURL -File $DNSHelper
}
2024-07-01 11:19:20 -04:00
$RefreshScript = $Global:ToolsDirectory + '\refresh-local-hosts.bat'
2024-07-01 11:24:24 -04:00
$todaysDate = Get-LongDate
2024-07-01 11:19:20 -04:00
$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)
2024-07-01 11:24:24 -04:00
REM Updated: ${todaysDate}`n
2024-07-01 11:19:20 -04:00
"@
2024-06-07 14:30:07 -04:00
$Resolvers = @(
'1.1.1.1',
'8.8.8.8',
'1.0.0.1',
'8.8.4.4'
)
$Hosts = @(
'auth.services.mspbackups.com',
'ws.mspbackups.com'
)
If ($BackupBucket.Length -ge 2 ) {
$Hosts += $BackupBucket
}
$ResolverString = ''
ForEach ($Resolver in $Resolvers) {
If ($ResolverString.Length -gt 0) { $ResolverString = $ResolverString + ',' + $Resolver }
Else { $ResolverString = $Resolver }
}
$HostString = ''
ForEach ($Hostname in $Hosts) {
If ($HostString.Length -gt 0) { $HostString = $HostString + ',' + $Hostname }
Else { $HostString = $Hostname }
}
If ( Test-Path $DNSHelper ) {
2024-07-01 11:19:20 -04:00
$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 }
2024-06-07 14:30:07 -04:00
Write-Output "Updating local hosts file with name-to-IP mappings for the following host(s): ${HostString}"
2024-07-01 11:19:20 -04:00
& "${RefreshScript}"
2024-06-07 14:30:07 -04:00
} Else {
Write-Error "Cannot find the DNS Helper executable: ""${DNSHelper}"""
}