The VBScript Network and Systems Administrator's Cafe

Mar 20 2009   4:32PM GMT

Writing a BGINFO like Script: Displaying DNS Server settings with WMI via the Win32_NetworkAdapterConfiguration class



Posted by: Jerry Lees
Tags:
bginfo
Systems Administration
Systems administrator tools
systems management
systems reporting
VBScript
VBScript Functions

I recently had to provide the information displayed with BGINFO on a number of systems. Unfortunately, BGInfo only generates a bitmap, so far as I know, so I decided to write a script to generate the information and use this displayed information to send back to the person who requested it.

The function below is a part of the script I mentioned. It retrieves and returns text that represents the DNS Server settings for the network adapters in the system.

You can view all the scripts in this BGINFO series here.

Here is the code:

Function GetDNSAddress(strComputer)
on error resume next
Dim colItems, objItem, address
Dim StrQuery
Dim objWMIService
Dim IP

StrQuery = “SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2″)
Set colItems = objWMIService.ExecQuery(strQuery,,48)

For Each objItem in colItems
For Each address In objItem.DNSServerSearchOrder
IP = replace(address,”:”,”")
‘IP = Replace(IP,vbnull,”No IP Assigned”)
GetDNSAddress = GetDNSAddress & vbTab & mid(objItem.caption,InStr(objItem.caption,”]”)+2) & “: ” & IP & vbcrLF
Next
Next
On Error GoTo 0
End Function

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: