mjm21
asked on
Powershell Script that would list network adapters ip address and status
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.
netsh interface ipv4 show interfaces
http://blogs.technet.com/b/heyscriptingguy/archive/2014/01/15/using-powershell-to-find-connected-network-adapters.aspx
get-netadapter
https://technet.microsoft.com/en-us/library/jj130867.aspx
http://blogs.technet.com/b/heyscriptingguy/archive/2014/01/15/using-powershell-to-find-connected-network-adapters.aspx
get-netadapter
https://technet.microsoft.com/en-us/library/jj130867.aspx
ASKER
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?
Will: Can we pipe this out to .csv file? Subnet should be like this: IE: 10.10.10.0 correct?
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
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
ASKER
ok thanks Carol
If you want to pipe it to CSV use my code below...
Will.
$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
}
Will.
ASKER
Hi Will,
Getting this error:
Missing closing '}' in statement block.
At line:4 char:2
Getting this error:
Missing closing '}' in statement block.
At line:4 char:2
My Mistake. I have corrected the code below...
I forgot to add the } bracket after "10.10.*"}
$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
}
I forgot to add the } bracket after "10.10.*"}
ASKER
ok - testing now. Also, as far as the ip address schema, not all the servers are on the same subnet.
ASKER
Will...another error:
Select-Object : Cannot convert System.Management.Automati on.PSObjec t to one of
the following types {System.String, System.Management.Automati on.ScriptB lock}.
At line:3 char:88
+ Get-WMIObject -Class Win32_NetworkAdapterConfig uration -ComputerName $Compute
r | select <<<< $Computer, DHCPEnabled, IPAddress, DefaultIPGateway, Descripti
on | out-file "c:\exportNetworkAdapters. csv" -append
+ CategoryInfo : InvalidArgument: (:) [Select-Object], NotSupport
edException
+ FullyQualifiedErrorId : DictionaryKeyUnknownType,M icrosoft.P owerShell. Co
mmands.SelectObjectCommand
Select-Object : Cannot convert System.Management.Automati
the following types {System.String, System.Management.Automati
At line:3 char:88
+ Get-WMIObject -Class Win32_NetworkAdapterConfig
r | select <<<< $Computer, DHCPEnabled, IPAddress, DefaultIPGateway, Descripti
on | out-file "c:\exportNetworkAdapters.
+ CategoryInfo : InvalidArgument: (:) [Select-Object], NotSupport
edException
+ FullyQualifiedErrorId : DictionaryKeyUnknownType,M
mmands.SelectObjectCommand
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
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.