Hey guys,
So I am making a script that joins a system to the domain and names it based on the service tag. Every part works flawlessly except the joining to the domain part. Im hoping someone can take a look at the code and help me understand why it isnt working:
I commented off the parts that are working (timers, name the computer, shut down after it runs etc..).
Basically the code runs through (verified with a message box) and just doesnt do anything, it wont add it to the domain (yes I am a domain admin).
So I am making a script that joins a system to the domain and names it based on the service tag. Every part works flawlessly except the joining to the domain part. Im hoping someone can take a look at the code and help me understand why it isnt working:
Code:
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Dim strComputer, strSN, oWMI, oCmp, oOS, sReturn, sUser, sPassword, sDomain, sOU
sUser = "<USERNAME>"
sPassword = "<PASSWORD>"
sDomain = "<DOMAIN>"
strComputer = "."
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
For Each oCmp in oWMI.InstancesOf("Win32_ComputerSystem")
sReturn = oCmp.JoinDomainOrWorkgroup(sDomain, sPassword, _
sDomain & "\" & sUser, sOU, JOIN_DOMAIN)
next
'wScript.sleep 20000
'Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
'For Each objSMBIOS in colSMBIOS
' strSN = objSMBIOS.SerialNumber
'If strSN <> "" Then exit For
'Next
'Set ws = WScript.CreateObject("WScript.Shell")
'value1 = "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\"
'value2 = "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\ParameterS\"
'ws.RegWrite value1 & "ComputerName", "WN7X64-" + strSN
'ws.RegWrite value2 & "NV Hostname", "WN7X64-" + strSN
'wScript.sleep 2000
'Dim oShell
'Set oShell = CreateObject("Wscript.Shell")
'sReturn = oShell.Run("%comspec% /c shutdown -r -t 0 -f")
Basically the code runs through (verified with a message box) and just doesnt do anything, it wont add it to the domain (yes I am a domain admin).