Home » PowerShell » DNS Forward Lookup (Hostname to IP) Script with Auto Generate Excel File

DNS Forward Lookup (Hostname to IP) Script with Auto Generate Excel File

Recent Tweets

Enter your email address to follow this blog and receive notifications of new posts by email.

Advertisements

###########################################################################
#
# NAME: DNS Forward Lookup Script with Auto Generate Excel File
#
# AUTHOR: J.Malek (www.malekjakir.com) Email: malek dot one zero four zero at gmail dot com
#
# COMMENT: This script can be used to check list of Servers for Forward NSLookup to get the IP Addresses.
# Line#29 - Please Change the path of Servers.txt to your file location.
# NOTE: One server name per line.
#
# VERSION HISTORY:
# 1.0 2/17/2012 -
#
###########################################################################
$ErrorActionPreference = "silentlycontinue"

$a = New-Object -comobject Excel.Application
$a.visible = $True
$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)
$c.Cells.Item(1,1) = "Server Hostname"
$c.Cells.Item(1,2) = "IP Address"
$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True
$intRow = 2

$colComputers = get-content "C:\SCRIPTS\DNS_Lookup\ForwardLookup\Servers.txt"
foreach ($strComputer in $colComputers)
{
$FWDIP = [System.Net.Dns]::GetHostAddresses($strComputer) | Add-Member -Name HostName -Value $strComputer -MemberType NoteProperty -PassThru | Select HostName, IPAddressToString

$c.Cells.Item($intRow,1) = $FWDIP.Hostname
$c.Cells.Item($intRow,2) = $FWDIP.IPAddressToString
$intRow = $intRow + 1
}
$d.EntireColumn.AutoFit()
cls
Write-Host "######## This Script is completed now ########"
Advertisements

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 )

Google+ photo

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

Twitter picture

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

Facebook photo

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

w

Connecting to %s

%d bloggers like this: