Link to home
Create AccountLog in
Avatar of REIUSA
REIUSAFlag for United States of America

asked on

Script to gather NIC name, IP and status

Does anyone have a script that will pull from a list of servers and output to cvs or txt and give me the name, status (enabled, disabled), and ip address of all the NIC's on the system?

Thanks,
Avatar of REIUSA
REIUSA
Flag of United States of America image

ASKER

Just found another issue. Is it possible to get this info with a simple command using Net, SC or something like that? The firewall is blocking VBS's.
Can you use WMI ? Have you ever used the command WMIC ?

Do "wmic /?" and you'll see you can grab just about any information from WMIC from local and remote machines. You can specify alternate credentials if needed as well.

This brief script below uses a text file named servers.txt that contains a list of machines I want to query. The next line uses WMIC to obtain the MAC & IP.

There are different format options. You could pipe the output to a file, which I did not do below. This outputs to the screen as CSV.

FOR /F %%i in (c:\servers.txt) do (
wmic /node:%%i NICCONFIG get MacAddress, IPaddress /format:CSV
)

You could tack on >> c:\output.csv to output to a file instead of the screen. the line would then read:

wmic /node:%%i NICCONFIG get MacAddress, IPaddress /format:CSV >> c:\output.csv

You have a bunch of options inside NICCONFIG too. You can tell it to only grab the information if the NIC is enabled or disabled. For instance:

wmic /node:%%i NICCONFIG WHERE IPEnabled="TRUE" get MacAddress, IPaddress /format:CSV

If you just want to work out the kinks on your local server first, just run the command as a single line and replace the %%i with the word localhost
Avatar of Sandeep
If you have all those Servers administered by Same Admin Account (Same User ID and Password) PSEXEC could be the key for you.

You simply have to mention the Hostnames in a flat text file one below the other. This file you can call in the PSEXEC Command and ask to execute ipconfig /all on it. This output you can save it in Text file for your reference.

command would be as below :-

psexec @ServerName.txt "ipconfig /all" > c:\Output.txt

You can customize your script as well. Refer to below
http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
I vote for the PSEXEC solution.  I use that extensively and successfully on a 15000 PC network.

- gurutc
Avatar of REIUSA

ASKER

I like the WMIC command but I am having a hard time getting the output I need. I need to know the name of the adapter too but I don't see a switch that will get that info. So if it is disabled I need to know it's disabled and what the actual name is like you would see it in Network Properties. Same for Enabled adapters.

I tried using ipconfig but it doesn't give me the info I need on the disabled NICs. just the enabled NIC's.
Can you use wmic /node:localhost nic get name

with my above script the /node would be /node:%%i

Do wmic /node:localhost get /?
   - to see what options you have with the command

or even just wmic /node:localhost nic /?
   - to see the switches you have available

there are a plenty of fields to can parse out
Avatar of REIUSA

ASKER

wmic /node:localhost nic get name

Seems to show the Device Name if you look at the Network Connections windows through the OS. I'm trying to get the name and IP of the adapter like what shows up in the Name field.

Like Disabled instead of "Cisco AnyConnect"

User generated image
how about:

wmic nicconfig get index,ipenabled,ipaddress,description

- gurutc
ASKER CERTIFIED SOLUTION
Avatar of ZabagaR
ZabagaR
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer