How to scan ip addresses range and get important details with Powershell GUI

Scan ip address range can help an IT Pro to identify active ip addresses in network. But with Powershell  can get more details like Operating System , Computer name , Serial Number , RAM etc. that can help to keep important details of all Servers and Workstations up to date. 

Two weeks ago i wrote an article How to resolve ip address to hostname with Powershell. The reason is that i try to create an asset management system that can scan an ip range and get back with some important details.

With this tool whenever i want i will have at least all my servers with all the details that i want up to date without need to download software's , install in separate Servers that has lot of features that most of the times are useless.

So let's take a look the changes that i have done in previous script.

The previous script in article How to resolve ip address to hostname with Powershell does the following tasks:

  • read a txt file with ip addresses
  • resolve it to hostnames

 

The new script include  a GUI and can do the following

  • give ip address range that you want in GUI environment
  • resolve the ip addresses to hostname's and write to datagridview 

 

Because i design the GUI in powershell most of the code is the GUI environment which include:

  • 1 Form
  • 3 textboxes
  • 3 Labels
  • 1 button
  • 1 Datagridview

You can find the full code here

Let's go in the most important lines of codes which is the scan of the ip address range, take the details that want and write to datagridview

After finish with the code of gui first line is to create an event in button

$button.Add_Click({

In the following 3 lines convert the startip and endip in integer  and the first3parts variable as string

The reason that convert the startip and endip is to can act as numbers and plus 1 in for-each loop

$a=[int]$startip.text
$b=[int]$endip.text
$c=[string]$textbox1.text

After I use the most quick way to scan ip range that you can find in article  POWERSHELL: PING IP RANGE of Thomas Mauer.

Then i create an object and add properties of ipaddrees and OS.

$a..$b | ForEach-Object {$o = new-object  psobject # New object
 $o | add-member -membertype noteproperty -name ipaddress -value (gwmi Win32_PingStatus -Filter "Address='$c.$_'").ProtocolAddress | Out-Null
 $o | add-member -membertype noteproperty -name OS -value (gwmi Win32_Operatingsystem -computername "$c.$_").Caption 
 
 $arr += $o
}

 

In the last lines select the properties of the object. Create an arraylist which add in datasource of datagridview. 
$arr | select-object -property ipaddress,OS
$arrlist=new-object System.Collections.ArrayList
$arrlist.AddRange($arr)
$datagridview.DataSource=$arrlist
})

 

The results are the following

 

The code is very basic without any catch of errors or results of important details after scan of the ip address range  but it's the first step.

I will continue to try and create better code with better results in next articles

Have a nice weekend !

I hope to find useful this article.

I invite you to follow me on Twitter , Google+ or Facebook. If you have any questions, send email to me at info@askme4tech.com.

Tags