Solved

Powershell Script that would list network adapters ip address and status

Posted on 2015-01-23
12
60 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
  • 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: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Remote Desktop to Server prints everything duplex 7 56
*** Hardware Malfunction Dell T610 7 87
can i use dropbox on a server used as a local share 8 126
Server 2016 licensing 11 661
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 listed in my profile here: http:…
The password reset disk is often mentioned as the best solution to deal with the lost Windows password problem. In Windows 2008, 7, Vista and XP, a password reset disk can be easily created. But besides Windows 7/Vista/XP, Windows Server 2008 and ot…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
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…

821 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