Skip to content

Instantly share code, notes, and snippets.

@jimfdavies
Last active September 28, 2018 14:06
Show Gist options
  • Save jimfdavies/4754650 to your computer and use it in GitHub Desktop.
Save jimfdavies/4754650 to your computer and use it in GitHub Desktop.
Get-DomainFromFQDN return the domain portion of a Fully-Qualified Hostname. This is currently limited to 4 sub-domains but the array selection could easily be extended to use the length of the array if appropriate. Useful for automatic deployment scripts.
Function Get-DomainFromFQDN {
param($fqdn)
$vmdomain = ($fqdn.split("."))[1..4]
$vmdomain = $vmdomain -join "."
return $vmdomain
}
$fqdn = "myhost.my.domain.local"
$domain = Get-DomainFromFQDN -fqdn $fqdn
$domain # "my.domain.local"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment