?
Solved

Powershell Script that would list network adapters ip address and status

Posted on 2015-01-23
12
Medium Priority
?
69 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip Migration Tip #1 – Source Server Health can be found here: http://www.experts-exchang…
INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
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). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Suggested Courses

765 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