'========================================================================== ' ' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1 ' ' NAME: Update DNS Search Order ' ' AUTHOR: Eric Woodford ' DATE : 10/26/2007 ' ' COMMENT: Queries current computer and determines if using old DNS Servers. ' Sets search order to NEW search order if so, otherwise does nothing. ' ' Script will also query SP and hard drive space free for basic info. ' ' SOURCE: http://www.microsoft.com/technet/scriptcenter/topics/networking/05_atnc_dns.mspx '========================================================================== On Error Resume Next Dim strComputer strComputer = "." arrNewDNSServerSearchOrder = Array("192.168.0.5", "192.168.0.6") Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colNicConfigs = objWMIService.ExecQuery _ ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") WScript.Echo VbCrLf & "Computer: " & strComputer For Each objNicConfig In colNicConfigs validDNS=False WScript.Echo VbCrLf & " Network Adapter " & objNicConfig.Index WScript.Echo " DNS Server Search Order - Before:" If Not IsNull(objNicConfig.DNSServerSearchOrder) Then For Each strDNSServer In objNicConfig.DNSServerSearchOrder WScript.Echo " " & strDNSServer ' if the DNS is currently set to the old server setting, change it. If InStr(strDNSServer,"192.168.1.5") Then validDNS=True If InStr(strDNSServer,"192.168.1.6") Then validDNS=True Next End If if validDNS Then intSetDNSServers = objNicConfig.SetDNSServerSearchOrder(arrNewDNSServerSearchOrder) If intSetDNSServers = 0 Then WScript.Echo " Replaced DNS server search order list." Else WScript.Echo " Unable to replace DNS server search order list." End If Else WScript.Echo " No valid DNS servers found to replace." End if Next WScript.Echo VbCrLf & String(80, "-") Set colNicConfigs = objWMIService.ExecQuery _ ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") For Each objNicConfig In colNicConfigs WScript.Echo VbCrLf & " Network Adapter " & objNicConfig.Index WScript.Echo " DNS Server Search Order - After:" If Not IsNull(objNicConfig.DNSServerSearchOrder) Then For Each strDNSServer In objNicConfig.DNSServerSearchOrder WScript.Echo " " & strDNSServer Next End If Next WScript.Echo VbCrLf & String(80, "-") OS = GetOS(strComputer) If OS <> "" Then SP = GetServicePack(strComputer) sDrives=GetFreeDriveSpace(strComputer) Else OS = "Not responding to script" SP = " " sDrives=" " IP = " " End If wscript.Echo OS&" : "&SP wscript.Echo sDrives '------------------------------- gather server information -------------------- Function GetOS(strComputer) Dim OS On Error Resume next Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems OS = objOperatingSystem.Caption &" "& objOperatingSystem.Version If InStr(OS," 2000 ") Then OS=TRIM(mid(OS,1,InStr(OS,"2000")+4))&","&TRIM(mid(OS,InStr(OS,"2000")+4,Len(OS))) Next GetOS = OS End Function Function GetServicePack (strComputer) On Error Resume next Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems GetServicePack = objOperatingSystem.ServicePackMajorVersion & "." & objOperatingSystem.ServicePackMinorVersion Next End Function Function GetFreeDriveSpace(strComputer) 'http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct04/hey1013.mspx On Error Resume next Dim AllHD Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colDisks = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk Where DriveType = 3") AllHD = "" For Each objDisk in colDisks intFreeSpace = objDisk.FreeSpace intTotalSpace = objDisk.Size pctFreeSpace = intFreeSpace / intTotalSpace AllHD= AllHD & objDisk.DeviceID &vbtab & FormatPercent(pctFreeSpace)&vbcrlf Next GetFreeDriveSpace=AllHD End Function