Powershell: Getting the IP Address, FQDN and MAC Address of Each Domain Controller

I was asked to get a baseline for generating reports within AD.  The two important pieces of information which were required to generate these reports were the ip address and FQDN of each domain controller.  The script would then connect to each individual system to gather data.  While I was at it, I added the MAC Address just to see what other pieces of data would be useful out of the Win32_NetworkAdapterConfiguration class.

#Enter the fqdn of your forest/domain
$fqdn = "fully.qualified.domain.name"
#Create Empty HashTable
$ht = New-Object psobject | Select FQDN, MACAddress, IPAddress

#Enumerate Domain Controllers
$context = new-object System.DirectoryServices.ActiveDirectory.DirectoryContext("Domain",$fqdn)
$dclist = [System.DirectoryServices.ActiveDirectory.DomainController]::findall($context)
ForEach ($strComputer in $dclist) {
	#Get IP Info of each DC
	$colItems = GWMI -cl "Win32_NetworkAdapterConfiguration" -name "rootCimV2" -comp `
                $strComputer.name -filter "IpEnabled = TRUE"
	ForEach ($objItem in $colItems){
        $ht.FQDN = $strComputer
        $ht.MACAddress = $objItem.MacAddress
        $ht.IPAddress = $objItem.IpAddress
	}
    $ht
}

1 comment

Comments are closed.