Month: September 2008

Finding Network Adapter with an active link

Recently, I wrote a small batch script to configure a bunch of systems with similar settings. In this process, I had to find out a NIC with an active connection to assign it an IP address. However, I could not find a straight forward way to do that in a batch script. I started looking at WMIC for some help and found that the following command could be of some help WMIC NIC where “NetConnectionStatus=’2′ and NetConnectionID=’Local Area Connection’” GET NetConnectionID /VALUE’ This command would resturn something like NetConnectionID=Local Area Connection. This isn’t really helpful considering the fact that we will not be able to use the complete string anywhere in our script. We need only the Local Area Connection part of the string. The workaround was to place this command in a FOR statement and retrieve the required value. Here is how I did that FOR /F “tokens=2 delims==,” %%i in (‘WMIC NIC where “NetConnectionStatus=’2′ and NetConnectionID=’Local Area Connection’” GET NetConnectionID /VALUE’) DO @set Connect1=%%i In the above command, NetConnectionStatus=’2′ is used to find if the …

WMIC – Windows Management Instrumentation Command-line

WMIC is a great tool to retrieve lot of useful system information without even writing a single line of code. I have used this for a while and find it really useful when scripting some repeated tasks such as enabling remote desktop on a group of systems, adding systems to Windows domain, etc, etc. It also provides a way to learn about Windows Management Instrumentation. Each alias is associated with a WMI class. You can find an association by using alias command at WMIC prompt. <Alias> /?, for example COMPUTERSYSTEM /? will provide help on how that object can be used to get/set information. Similarly, you can use the help option to see understand each option available. This is a standard set of options for all objects within WMIC. CALL option within this list if something interesting. If you check for help on this, you will actually see a list of all methods available under this WMI class. This provides a great way to learn about WMI classes and method. You can also correlate this to …