Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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
2
Medium Priority
?
129 Views
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!!!!!!
0
Comment
Question by:NAMEWITHELD12
2 Comments
 
LVL 65

Accepted Solution

by:
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


Regards,

Rob.
0
 
LVL 1

Author Closing Comment

by:NAMEWITHELD12
ID: 40623834
Thanks tons !!!

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

THANKS AGAIN !!!!!
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to dynamically set the form action using jQuery.
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 anti-spam), the admin…
Suggested Courses

971 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