ps/Modules/Alkami.PowerShell.Configuration/Public/New-WebTierHostFileEntries.ps1

46 lines
1.4 KiB
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function New-WebTierHostFileEntries {
<#
.SYNOPSIS
Creates a Host File Entry for the Supplied URL Pointed to the Loopback IP
.DESCRIPTION
Creates a Host File Entry for the Supplied URL Pointed to the Loopback IP
.PARAMETER Url
[string] DNS entry to put map to loopback in HOSTS file
.NOTES
Target for future deprecation. This could be an inline func from the caller
.EXAMPLE
New-WebTierHostFileEntries "www.foo.bar"
[Add-HostsFileContent] : Adding Hosts Entry : 127.0.0.1 www.foo.bar
[Add-HostsFileContent] : Saving Modified Hosts File to C:\WINDOWS\System32\Drivers\etc\hosts
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[string]$Url
)
$logLead = (Get-LogLeadName);
$hostsContent = Get-HostsFileContent
$hostsString = "127.0.0.1{0}{1}"
$cleanedUrl = (Format-Url -url $Url)
$hostsRegex = "^127\.0\.0\.1\s+$cleanedUrl"
if (($hostsContent | Where-Object {$_ -match $hostsRegex }).Count -gt 0) {
Write-Warning ("$logLead : LOOPBACK Hosts File Entry for URL {0} Already Exists" -f $cleanedUrl)
return
}
$newHostsEntry = ($hostsString -f "`t`t", $url)
Write-Verbose "$logLead : Calling Add-HostsFileContent with -Force flag"
Add-HostsFileContent -contentToAdd $newHostsEntry -Force
}
Set-Alias -name Create-WebTierHostFileEntries -value New-WebTierHostFileEntries;