46 lines
1.4 KiB
PowerShell
46 lines
1.4 KiB
PowerShell
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; |