Solved

Powershell Script that would list network adapters ip address and status

Posted on 2015-01-23
12
66 Views
Last Modified: 2015-06-18
Powershell Script that would list all network adapters ip address and status gathered from a list of computers in a .txt file.  The output should be exported to a .csv file.
0
Comment
Question by:mjm21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40566870
Use the following script below...
$List = get-content "c:\name.txt"
foreach ($Computer in $List) {
Get-WMIObject -Class Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPAddress -like "10.10.*" | ft $Computer, DHCPEnabled, DefaultIPGateway, Description
}

Open in new window


 The script above will take each computer and from your list and only reply the values of the network adapter that actually has IP address associated to it. This is helpful because if this is not present it will present all adapters like IPv6 Tunneling etc.

You will also need to change the 10.10.* to whatever your internal IP scheme is.

Will.
0
 
LVL 16

Expert Comment

by:Carol Chisholm
ID: 40566880
0
 

Author Comment

by:mjm21
ID: 40566965
Thanks to both of you!  

Will:  Can we pipe this out to .csv file?  Subnet should be like this:  IE: 10.10.10.0 correct?
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 16

Expert Comment

by:Carol Chisholm
ID: 40567008
Powershell export to csv
http://blogs.technet.com/b/heyscriptingguy/archive/2014/02/04/use-powershell-to-create-csv-file-to-open-in-excel.aspx

for command line (netsh works from both powershell and command line) just add > c:\outputfile.csv
0
 

Author Comment

by:mjm21
ID: 40567046
ok thanks Carol
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40568172
If you want to pipe it to CSV use my code below...

$List = get-content "c:\name.txt"
foreach ($Computer in $List) {
Get-WMIObject -Class Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPAddress -like "10.10.*" | select $Computer, DHCPEnabled, IPAddress, DefaultIPGateway, Description | out-file "c:\exportNetworkAdapters.csv" -append
}

Open in new window


Will.
0
 

Author Comment

by:mjm21
ID: 40575196
Hi Will,

Getting  this  error:

Missing closing '}' in statement block.
At line:4 char:2
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40575226
My Mistake. I have corrected the code below...

$List = get-content "c:\name.txt"
foreach ($Computer in $List) {
Get-WMIObject -Class Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPAddress -like "10.10.*"} | select $Computer, DHCPEnabled, IPAddress, DefaultIPGateway, Description | out-file "c:\exportNetworkAdapters.csv" -append
}

Open in new window


I forgot to add the } bracket after "10.10.*"}
0
 

Author Comment

by:mjm21
ID: 40575634
ok - testing now.  Also, as far as the ip address schema, not all the  servers are on  the same subnet.
0
 

Author Comment

by:mjm21
ID: 40575976
Will...another  error:

Select-Object : Cannot convert System.Management.Automation.PSObject to one of
the following types {System.String, System.Management.Automation.ScriptBlock}.
At line:3 char:88
+ Get-WMIObject -Class Win32_NetworkAdapterConfiguration -ComputerName $Compute
r | select <<<<  $Computer, DHCPEnabled, IPAddress, DefaultIPGateway, Descripti
on | out-file "c:\exportNetworkAdapters.csv" -append
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], NotSupport
   edException
    + FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Co
   mmands.SelectObjectCommand
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40576078
Ok try using FT instead of select. See below...

$List = get-content "c:\name.txt"
foreach ($Computer in $List) {
Get-WMIObject -Class Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPAddress -like "10.10.*"} | FT $Computer, DHCPEnabled, IPAddress, DefaultIPGateway, Description | out-file "c:\exportNetworkAdapters.csv" -append
}                                          

Open in new window

0
 
LVL 1

Accepted Solution

by:
smahi earned 500 total points
ID: 40756154
Check this out simple and fast one

$servers = get-content List_of_Servers.txt
$serversAndIps = "List_of_servers_with_ips.csv"

$results =@()
  foreach ($server in $servers )
   {
	$result=@() 
	$result = "" | Select ServerName , IPaddress
	$result.IPaddress = (test-connection -computername $server -count 1 | select -expand "IPV4Address")
	$result.servername = $server
	$results += $result
   }
   
$results | export-csv -NoTypeInformation $serversandips

Open in new window

0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Issue: One Windows 2008 R2 64bit server on the network unable to connect to a buffalo Device (Linkstation) with firmware version 1.56. There are a total of four servers on the network this being one of them. Troubleshooting Steps: Connect via h…
Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

733 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