Get all DCs in a forest and resolve hostname to IP address
Get all DCs in a forest and resolve hostname to IP address

With this script, you will be able to get all DCs in a forest and resolve the hostnames to IP addresses.

Update 11.22.2016
The DNS Shell cmdlet is not necessary in a Windows 2012R2 environment. We can use the cmdlet resolve-DnsName to do the job. The script is now the following

$myForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$myforest.Sites.Servers.Name | % {
	write-host $_"`t"(resolve-DnsName -name $_).IPAddress
}

Old script version for Windows OS 2008R2 and older
The pre-requesite to run this script is to install the DNS Shell cmdlets (http://dnsshell.codeplex.com/)

Script :

$myForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$hosts = $myforest.Sites | % { $_.Servers } | select Name
foreach ($hostname in $hosts) {
	Get-Dns $hostname.Name | select Answer
}

References

DNS Shell cmdlets

DnsShell is a Microsoft DNS administration / management module written for PowerShell 2.0
Bugs, issues and suggestions

Please do report any and all bugs you experience using this module (or failing to use this module). Hopefully Discussions and Issue Tracker on here will allow that. If not, please drop a comment onto my blog (or e-mail me if you can guess my easy-to-guess address):

http://www.indented.co.uk/index.php/category/dnsshell/

I’ll either raise it as an issue or fix it (depending on severity / difficulty).

The same applies for issues and suggestions.
Installation

Extract DnsShell.zip to one of the paths shown by $Env:PSModulePath
Run: Import-Module DnsShell

Notes (issues that will not effect module functionality):
Import-Module will throw an error on import if the Execution Policy requires all files to be signed. The format file is not signed.

DNS Resolver

Get-Dns

WMI Wrappers

Clear-DnsCache
Get-DnsRecord
Get-DnsServer
Get-DnsZone
New-DnsRecord
New-DnsZone
Remove-DnsObject
Reset-DnsZoneType (no Get-Help)
Resume-DnsZone
Set-DnsRecord (no Get-Help)
Set-DnsServer (to be completed)
Set-DnsZone (to be completed)
Set-DnsZoneTransfer (no Get-Help)
Start-DnsScavenging
Start-DnsService
Stop-DnsService
Suspend-DnsZone
Update-DnsZone
Update-DnsZoneFile

Active Directory

Get-ADDnsPartition
Get-ADDnsRecord
Get-ADDnsZone
New-ADDnsRecord (to be completed)
New-ADDnsZone (to be completed)
Remove-ADDnsRecord (to be completed)
Remove-ADDnsZone (to be completed)
Set-ADDnsRecord (to be completed)
Set-ADDnsZone (to be completed)
<>
Get all DCs in a forest and resolve hostname to IP address

Leave a Reply

Your email address will not be published.