如何远程将工作组计算机加入域

时间:2012-08-11 00:19:10

标签: vbscript dns workgroup ou

场景:我在具有管理员凭据的域中使用ComputerA。远程计算机B(具有已知的管理员凭据)位于工作组中。 ComputerB需要加入指定OU中的特定域(不同于ComputerA),我的活动ComputerA凭据有权使用该域。我不能使用NETDOM等外部程序,而更喜欢使用VBScript。

非常感谢任何帮助!

2 个答案:

答案 0 :(得分:0)

试试这个,我改编了http://www.tek-tips.com/viewthread.cfm?qid=1240726

的一段脚本
strComputer = "ComputerB"
strPassword = "mypassword"
strDomain   = "mydomain"
strUser     = "myusername"

Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
    strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
        strComputer & "'")

ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & "\" & strUser, "ou=My_Computer_OU,DC=mycorp,dc=com, _
        JOIN_DOMAIN + ACCT_CREATE)

If ReturnValue = 0 Then
    MsgBox "Computer added to domain under old name without error. proceeding to change computer name. "
Else
    MsgBox "Computer not added to domain successfully. Return value: " & ReturnValue
End If

答案 1 :(得分:0)

我实际上能够自己解决这个问题。这是未来编码员的代码:

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

Const WbemAuthenticationLevelPktPrivacy = 6

SystemName = "ComputerB"
strNamespace = "root\cimv2"
ComputerBLogin= "Login"
ComputerBPass = "Password"
ComputerALogin = "Login"
ComputerAPass = "Password"
DomainName = "domain.com"
OU = "OU=desiredou,DC=domain,DC=com"

Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")

Set objWMIService = objwbemLocator.ConnectServer(SystemName, strNamespace, ComputerBLogin, ComputerBPass)

objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy

Set colComputers = objWMIService.ExecQuery _
    ("Select * From Win32_ComputerSystem")
For Each objComputer in colComputers
    ReturnValue = objComputer.JoinDomainOrWorkGroup(DomainName, ComputerAPass, ComputerALogin, OU, JOIN_DOMAIN + ACCT_CREATE)
Next

If Err.Number <> 0 Then
    Set WshShell = CreateObject("WScript.Shell")
    message = WshShell.Popup ("Unable to join " & SystemName & " to the domain! Please join manually.",, "Error", 0 + 16)
Else
    Set WshShell = CreateObject("WScript.Shell")
    message = WshShell.Popup ("Domain joining was successful!",, "Success!", 0 + 64)
End If

Err.Clear