Is there any way to modify static DNS entries remotely on Win2K servers?
Announcement
Collapse
No announcement yet.
Remote DNS modifications
Collapse
X
-
Re: Remote DNS modifications
A scripting solution, similar to this, may be a solution. WMI might be able to do what you want, but I haven't found anything to "PUT" the information, only gather it.
http://www.serverwatch.com/tutorials...le.php/1476991
Comment
-
Re: Remote DNS modifications
Not sure if this is the solution you're looking for...
http://www.free2code.net/code/vb/6/code_164.php
...hope it helps!
Joel
Comment
-
Re: Remote DNS modifications
With a little tweaking, it does exactly what I want...Modified code below (removed the auto-reboot since this is not what I want it to do.). I will also be removing the action prompts so it can run unattended. I don't think I can create a custom tool, since the servername(s) are specified in the code, not as a switch, but I will look into it. If anyone else can fix this, please post here.
For original code, use link above.
___________________________________________
' IMPORTANT !!!! Change these constants !!!!
Const STR_SERVERS = "ServerA ServerB" ' Enter your servers here, separated by a space
Const STR_NEWDNS1 = "192.168.0.1"
Const STR_NEWDNS2 = "192.168.0.2"
Const STR_NEWWINS1= "192.168.0.1"
Const STR_NEWWINS2= "192.168.0.2"
' ///////////////////////////////////////////////////////////////////////////////////////////////
Do
cKeuze = MakeChoise( "Choose: Report or Change (R/C)?" )
Loop until cKeuze = "C" Or cKeuze = "R"
WScript.Echo
If( cKeuze = "C" ) Then
Change( STR_SERVERS )
Else
Report( STR_SERVERS )
End If
WScript.Echo( "Check out http://www.activxperts.com for more samples and components" )
' ///////////////////////////////////////////////////////////////////////////////////////////////
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub Change( strParamServers )
arrServers = Split( strParamServers, " " )
For i = 0 To UBound( arrServers )
ShowDnsWins arrServers( i )
Do
cKeuze = MakeChoise( " Change DNS/WINS (y/n)?" )
Loop until cKeuze = "Y" Or cKeuze = "N"
If( cKeuze = "Y" ) Then
SetDnsWins arrServers( i )
End If
WScript.StdOut.Write( vbCrlf )
Next
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub Report( strParamServers )
arrServers = Split( strParamServers, " " )
For i = 0 To UBound( arrServers )
ShowDnsWins arrServers( i )
Next
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub ShowDnsWins( strServer )
strWinMgmt = "winmgmts:{impersonationLevel=impersonate}!//"& strServer &""
Set objNICs = GetObject( strWinMgmt ).InstancesOf( "Win32_NetworkAdapterConfiguration" )
WScript.StdOut.Write( strServer & ": " & vbCrlf )
For Each objNIC In objNICs
If objNIC.IPEnabled Then
WScript.StdOut.Write( " " & objNIC.Description & ": " & vbCrlf & " " )
n = 1
For Each strDns In objNIC.DNSServerSearchOrder
WScript.StdOut.Write "DNS" & n & ":" & strDns & " "
n = n + 1
Next
WScript.StdOut.Write( vbCrlf )
End If
Next
WScript.StdOut.Write( vbCrlf )
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub SetDnsWins( strServer )
strWinMgmt = "winmgmts:{impersonationLevel=impersonate}!//"& strServer &""
Set objNICs = GetObject( strWinMgmt ).InstancesOf( "Win32_NetworkAdapterConfiguration" )
WScript.StdOut.Write( " Set DNS for NIC: " )
For Each objNIC In objNICs
If objNIC.IPEnabled Then
objNIC.SetWINSServer STR_NEWWINS1,STR_NEWWINS2
objNIC.SetDNSServerSearchOrder Array(STR_NEWDNS1,STR_NEWDNS2)
WScript.StdOut.Write objNIC.Description & " "
End If
Next
WScript.StdOut.Write( vbCrlf )
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Function MakeChoise( strMesg )
WScript.StdOut.Write(strMesg)
WScript.StdIn.Read(0)
strChoise = WScript.StdIn.ReadLine()
MakeChoise = UCase( Left( strChoise, 1 ) )
End Function
____________________________________________
Comment
-
Re: Remote DNS modifications
I see using this to modify static settings on a group of computers, so ideally, it would have to be able to accomodate multiple name selections (Selecting SERVERS in the left pane, and selecting all servers in the right pane and executing the command).
This would not be used often, but if you have a DNS servers IP or preference change, then all of your static entries could be changed almost as easily as your DHCP scopes.
Comment
-
Re: Remote DNS modifications
Lemme know if this does the trick:
Click on Servers (or Computers) in the left pane, then select the systems you wish to run this tool on (max is 20, don't forget).
'***** script starts here ***********
Dim WshShell : Set WshShell = WScript.CreateObject("WScript.Shell")
Dim WshNetwork : Set WshNetwork = WScript.CreateObject("WScript.Network")
Dim objArgs : Set objArgs = WScript.Arguments ' create object with collection
If objArgs.Count >= 1 Then
strTargetComp = objArgs(0) ' assign the passed computer name to a variable
Else
strResponse = MsgBox ("Do you wish to run this script on the local machine?", vbYesNo + vbQuestion + vbDefaultButton2, "Run this on the local machine?")
If strResponse = vbNo Then
WScript.Quit
Else
strTargetComp = WshNetwork.ComputerName
End If
End If
' IMPORTANT !!!! Change these constants !!!!
Const STR_NEWDNS1 = "192.168.0.1"
Const STR_NEWDNS2 = "192.168.0.2"
Const STR_NEWWINS1= "192.168.0.1"
Const STR_NEWWINS2= "192.168.0.2"
' ///////////////////////////////////////////////////////////////////////////////////////////////
Do
cKeuze = MakeChoise( "Choose: Report or Change (R/C)?" )
Loop until cKeuze = "C" Or cKeuze = "R"
If( cKeuze = "C" ) Then
Change
Else
Report
End If
' ///////////////////////////////////////////////////////////////////////////////////////////////
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub Change
ShowDnsWins strTargetComp
Do
cKeuze = MakeChoise( " Change DNS/WINS (y/n)?" )
Loop until cKeuze = "Y" Or cKeuze = "N"
If( cKeuze = "Y" ) Then
SetDnsWins strTargetComp
'RebootServer strTargetComp ' remove the mark to reboot
End If
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub Report
ShowDnsWins
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub ShowDnsWins
On Error Resume Next ' needed in case an adapter has no DNS settings
strWinMgmt = "winmgmts:{impersonationLevel=impersonate}!//"& strTargetComp &""
Set objNICs = GetObject( strWinMgmt ).InstancesOf( "Win32_NetworkAdapterConfiguration where IPEnabled=TRUE" )
WScript.StdOut.Write( strTargetComp & ": " & vbCrlf )
For Each objNIC In objNICs
If objNIC.IPEnabled Then
WScript.StdOut.Write( " " & objNIC.Description & ": " & vbCrlf & " " )
n = 1
For Each strDns In objNIC.DNSServerSearchOrder
WScript.StdOut.Write "DNS" & n & " : " & strDns & vbCrLf
n = n + 1
Next
WScript.StdOut.Write( vbCrlf )
End If
Next
WScript.StdOut.Write( vbCrlf )
On Error Goto 0
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub SetDnsWins
strWinMgmt = "winmgmts:{impersonationLevel=impersonate}!//" & strTargetComp
Set objNICs = GetObject( strWinMgmt ).InstancesOf( "Win32_NetworkAdapterConfiguration" )
WScript.StdOut.Write( " Set DNS for NIC: " )
For Each objNIC In objNICs
If objNIC.IPEnabled Then
objNIC.SetWINSServer STR_NEWWINS1,STR_NEWWINS2
objNIC.SetDNSServerSearchOrder Array(STR_NEWDNS1,STR_NEWDNS2)
WScript.StdOut.Write objNIC.Description & " "
End If
Next
WScript.StdOut.Write( vbCrlf )
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Function MakeChoise( strMesg )
WScript.StdOut.Write(strMesg)
WScript.StdIn.Read(0)
strChoise = WScript.StdIn.ReadLine()
MakeChoise = UCase( Left( strChoise, 1 ) )
End Function
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub RebootServer( strServer )
Set OpSysSet = GetObject("winmgmts:{(RemoteShutdown)}//" & strTargetComp & "/root/cimv2").ExecQuery("Select * from Win32_OperatingSystem where Primary=True")
WScript.StdOut.Write( " Reboot: " )
For Each OpSys In OpSysSet
WScript.StdOut.Write OpSys.Name
OpSys.Reboot()
Next
WScript.StdOut.Write( vbCrlf )
End Sub
'******** script ends here *******
I put the reboot sub back in, but REM'd it out in the main portion, just in case.
Comment
Comment