Domain join script sets static DNS server address instead of DHCP
I am using a join domain and rename post install task from this KACE article:
http://www.kace.com/support/resources/kb/article/How-to-rename-a-computer-and-join-it-to-a-Windows-domain-Image-Deployment
But the join_domain.vbs script sets a static DNS server which it does not remove and therefore causes issues when connecting to a different network (The DNS server address by the way is pulled from the JoinDomain.bat script downloaded in the same package (explained in the KACE article).
My VB scripting is rubbish so does anyone know how I can change the script syntax to pull a DNS server address from DHCP instead of setting it statically?
Syntax:
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
If WScript.Arguments.Count < 3 or WScript.Arguments.Count > 4 Then
WScript.Quit
Else
strDomain = WScript.Arguments.Item(0)
strUser = WScript.Arguments.Item(1)
strPassword = WScript.Arguments.Item(2)
'set DNS IP address
If WScript.Arguments.Count = 4 Then
strDNSIP = WScript.Arguments.Item(3)
Set objShell = CreateObject("WScript.shell")
objShell.Run "netsh int ip set dns ""local area connection"" static "& _
strDNSIP &" primary",0,0
End If
End If
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & _
"\root\cimv2:Win32_ComputerSystem.Name='" _
& strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, _
strDomain & "\" & strUser, _
NULL, _
JOIN_DOMAIN+ACCT_CREATE)
http://www.kace.com/support/resources/kb/article/How-to-rename-a-computer-and-join-it-to-a-Windows-domain-Image-Deployment
But the join_domain.vbs script sets a static DNS server which it does not remove and therefore causes issues when connecting to a different network (The DNS server address by the way is pulled from the JoinDomain.bat script downloaded in the same package (explained in the KACE article).
My VB scripting is rubbish so does anyone know how I can change the script syntax to pull a DNS server address from DHCP instead of setting it statically?
Syntax:
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
If WScript.Arguments.Count < 3 or WScript.Arguments.Count > 4 Then
WScript.Quit
Else
strDomain = WScript.Arguments.Item(0)
strUser = WScript.Arguments.Item(1)
strPassword = WScript.Arguments.Item(2)
'set DNS IP address
If WScript.Arguments.Count = 4 Then
strDNSIP = WScript.Arguments.Item(3)
Set objShell = CreateObject("WScript.shell")
objShell.Run "netsh int ip set dns ""local area connection"" static "& _
strDNSIP &" primary",0,0
End If
End If
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & _
"\root\cimv2:Win32_ComputerSystem.Name='" _
& strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, _
strDomain & "\" & strUser, _
NULL, _
JOIN_DOMAIN+ACCT_CREATE)
1 Comment
[ + ] Show comment
Answers (2)
Answer Summary:
Added the following command to the end of the script: netsh interface ip set dns "Local Area Connection" source=dhcp
Added the following command to the end of the script: netsh interface ip set dns "Local Area Connection" source=dhcp
Please log in to answer
Posted by:
LiamSinton
12 years ago
I have managed to accomplish this by adding the following command to the end of my JoinDomain.bat script (not that anybody seems interested)
netsh interface ip set dns "Local Area Connection" source=dhcp
Comments:
-
I'm interested and thanks for the help. I had the same issue - InterneToughGuy 11 years ago
-
Perfect... thank you... that worked - binuani 11 years ago
-
Thank you! I've been having this issue also! - tatkinson 9 years ago
Netsh
It can be scripted using Netsh
IPv4:
netsh interface ipv4 set dnsservers name="Local Network Area" source=dhcp register=none
IPv6:
netsh interface ipv6 set dnsservers name="Local Network Area" source=dhcp register=none
Not sure where it can be add in or tweaked - colleen.murray 6 years ago