Sometimes a DBA or developer requests what aliases are pointing to a given machine. To quickly facilitate this request for them, I came up with the script below. I thought there would be a way to accomplish this task with NSLOOKUP or DNSCMD, but I couldn't get it working. If you now of a way to get this working with only one of those tools, please post it in the comments.
function Get-DNSAlias
{
Param([string] $computername=$env:computername)
if ($_) {$computername=$_}
echo "Aliases for $computername"
$aliases = dnscmd computername /enumrecords domain.com . /type CNAME
foreach($alias in $aliases){$alias | % {$_.split(" ")[0]} | where {$alias.Contains($computername)}
}
<#
.SYNOPSIS
Gathers DNS CNAME records for the given host
.EXAMPLE
Get-DNSAlias computername
.DESCRIPTION
This command gathers and reports all of the CNAME records for the given computer in the hardcoded domain list
#>
}#end Get-DNSAlias
0 comments:
Post a Comment