I am looking for a power shell script to ask the user for a range and ping and report back hostname

Posted on 2015-02-20
Medium Priority
Last Modified: 2015-02-21
I am looking for a power shell script to ask the user for a range and ping and report back hostname

Thanks for the help!!!!!!
Question by:NAMEWITHELD12
LVL 65

Accepted Solution

RobSampson earned 2000 total points
ID: 40622650
Hi there,

This may not be the most efficient way to do this, but it does work.  Try out this Powershell code:
$startrange = read-host "Enter a start IP"
$endrange = read-host "Enter an end IP"
$startsubnet = "$($startrange.Split(".")[0]).$($startrange.Split(".")[1]).$($startrange.Split(".")[2])."
$endsubnet = "$($endrange.Split(".")[0]).$($endrange.Split(".")[1]).$($endrange.Split(".")[2])."
if ($startsubnet -eq $endsubnet) {
    $startip = $($startrange.Split(".")[3])
    $endip = $($endrange.Split(".")[3])
    $startip..$endip | foreach{test-connection -ComputerName $startsubnet$_ -count 1} | select -expandproperty ipv4address | select -expandproperty ipaddresstostring | foreach{[System.Net.Dns]::GetHostByAddress("$_")}
} else {
    write-host "Start subnet was not the same as the end subnet"

Open in new window



Author Closing Comment

ID: 40623834
Thanks tons !!!

I want to learn more about this and will post another question now about this !


Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
In an Exchange Crossforest migration, the distribution groups can be a very complex operation that would cause loss of time, lots of issues and continued headaches if not solved in a timely manner. I had to do a similar project so I created a sc…
The viewer will learn how to count occurrences of each item in an array.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

586 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question