I am trying to write a script to validate that the forward and reverse lookup of a IP match. With multiple DNS zones I may have multiple periods in the FQDN so the code I have below does not work all the time. For example split -3 will give me the shortname server1 if the FQDN server1.domain.local. However if the FQDN is server1.sub.domain.local the result would be blank.
My question would be how do I take the result that is left of the first period set it as a variable, then also variable for everything to the right of the first period?
$shortname = resolve-dnsname 192.168.0.1 | %{$_.NameHost} | ForEach-Object{$_.Split(".")[-3]} Write-Host $shortname
$longname = resolve-dnsname 192.168.0.1 | %{$_.NameHost} | ???????