Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save smaglio81/4697a8611825dd8f888d96833ebfb4d0 to your computer and use it in GitHub Desktop.
Save smaglio81/4697a8611825dd8f888d96833ebfb4d0 to your computer and use it in GitHub Desktop.
The name kind of covers it. For example https://unittest.some.company.com should have an application pool of unittest.some.company.com. A second example would be https://unittest.some.company.com/subsitea/ should have an application pool of unittest.some.company.com_subsitea.
<#
.SYNOPSIS
Enforces the formatting standards for application pool names.
This should be used to figure out the application pool name before creating an
new one. The name is also used to create unique ARR rule names.
.PARAMETER Url
The url to parse and convert to our standardized app pool name.
.PARAMETER Environment
If an environment is also passed, the url will be run through Get-WebEnvironmentUri
before being parsed/converted.
.LINK
Get-WebEnvironmentUri
.EXAMPLE
$url = "http://unittest.{env}.place.something.com"
$env = "dev"
$appPoolName = ConvertTo-UrlBasedAppPoolName -Url $url -Environment $env
#>
Function ConvertTo-UrlBasedAppPoolName {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[string] $Url
)
$parseUrl = $Url
$m = "(https?://)?(.*)"
if($parseUrl -match $m) {
$hostPath = $Matches[2]
}
$hostPath = $hostPath.Replace("/","_")
# this prevents http://aaa.sa.ucsb.edu/ from becoming aaa.sa.ucsb.edu_
$pathLen = $hostPath.Length;
if($pathLen -gt 0) {
if($hostPath[$pathLen - 1] -eq "_") {
$hostPath = $hostPath.Substring(0, $pathLen - 1);
}
}
return $hostPath.ToLower()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment