Use Powershell, WMI to retrieve DNS search order, Use Active Directory for list of computers.

# ********************* Global variables *********************
$sb =  new-object System.Text.StringBuilder
$sbErrors =  new-object System.Text.StringBuilder


# ********************* Defining functions *********************
function GetListOfComputer
{
$strCategory = “computer”
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher


$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = (“(objectCategory=$strCategory)”)


$colProplist = “name”
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}


$colResults = $objSearcher.FindAll()


foreach ($objResult in $colResults)
 {
  $objComputer = $objResult.Properties; $objComputer.name
  [string]$CN = $objComputer.name
  $ipaddress = Ping-Address $objComputer.name
  FOREACH-OBJECT {LogInfo $CN $ipaddress}
 }
}


function Ping-Address ([string]$strComputerName)
{
 $ipaddress = [System.Net.Dns]::GetHostbyName(“$strComputerName”) | select AddressList
 $strGetIPAddress = $ipaddress.AddressList[0].IpAddressToString
 Return $strGetIPAddress
}


function LogInfo ([string]$strServerName, [string]$strIPAddress)
{
  Write-Host $strServerName + “,” + $strIPAddress
  $pingresult = Get-WmiObject win32_pingstatus -Filter “address=’$strIPAddress'”
  $error.Clear()
  $ErrorActionPreference = “SilentlyContinue”
 
  if($pingresult.statuscode -eq 0)
   {
    trap [Exception] {continue}
    $colItems = get-wmiobject -query “Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = 1” -namespace “rootcimv2” -computername $strIPAddress
    foreach ($objItem in $colItems)
    {
         $strCaption =  $objItem.Caption
         write-host $strCaption


         $strDescription =  $objItem.Description
         write-host $strDescription


         $strDNSServerSearchOrder = $objItem.DNSServerSearchOrder
         write-host $strDNSServerSearchOrder


         $result = $strServerName + “,” + $strIPAddress + “,” + $strDNSServerSearchOrder + “,” + $strCaption + “,” + $strDescription + “`r”
         $sb.Append($result)
    }
   }
  else
   {
    Write-Host “Cannot connect:” + $strServerName + “,” + $strIPAddress
    $sbErrors.AppendLine($strServerName + “,” + $strIPAddress + “`r”)
    }
}



# ********************* Get list of Computers and call function to get data *********************
GetListOfComputer


# ********************* Write out data *********************
write-output $sb.ToString() >E:TempComputerList.txt
write-output $sbErrors.ToString() >E:TempComputerListNotFound.txt


 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: