none
Автоматизация не удаленного ввода в домен. RRS feed

  • Общие обсуждения

  • Добрый день. Подскажите если ли скрипт ввода компьютера в домен локальным администратором. Порядок действий такой:

    Система установлена

    Вход под локалтным админом

    Запуск скрипта который предложит ввести новое имя компа

    Вввод имени компьютера

    Комп в домене

    Где взять или из какого примера как переделать подскажите.

    17 апреля 2013 г. 7:02

Все ответы

  • VBS rename computer and join domain

    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
    Dim message
    Dim IP

    'Change domain, username and password here
    strDomain = "domain.com"
    strUser = "usernamewithdomainprivs"
    strPassword = "password"
     
    Set objNetwork = CreateObject("WScript.Network")
    strComputer = objNetwork.ComputerName
     
    Set objWMIService = GetObject ("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
    Set colAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")

    title = "Join computer to domain"
    message = "Please enter computer name. Leave blank or press cancel to quit." & vbCrLf & vbCrLf & "Generated name: " & generatedName
    newComputerName = InputBox(message, title)


    If newComputerName = "" Then
        Wscript.quit
    End If

    areYousure = MsgBox("Are you sure you want to add computer to domain with name:" & vbCrLf & vbCrLf & newComputerName, vbYesNo + vbQuestion,"Add computer to domain")

    If areYouSure = "7" Then
        MsgBox "Exiting script.",vbInformation
        Wscript.quit
    End If

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

    'Change OU here (Default is "OU=Computers,DC=domain,DC=com")
    ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & "" & strUser, "OU=My Computers,OU=Computers,DC=domain,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

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colComputers = objWMIService.ExecQuery _
        ("Select * from Win32_ComputerSystem")


    For Each objComputer in colComputers
        MsgBox "About to rename computer to: " & newComputername
            ErrCode = objComputer.Rename(newComputerName, strPassword, strUser)
        If ErrCode = 0 Then
            MsgBox "Computer renamed correctly."
        Else
            MsgBox "Eror changing computer name. Error code: " & ErrCode
        End If

    Next





    • Изменено KazunEditor 17 апреля 2013 г. 7:31
    17 апреля 2013 г. 7:18
    Отвечающий
  • Так.. сейчас он выглядит так:

    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
    Dim message
    Dim IP
    
    'Change domain, username and password here
    strDomain = "мой домен"
    strUser = "логин"
    strPassword = "пароль"
     
    Set objNetwork = CreateObject("WScript.Network")
    strComputer = objNetwork.ComputerName
     
    Set objWMIService = GetObject ("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
    Set colAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
    
    title = "Join computer to domain"
    message = "Please enter computer name. Leave blank or press cancel to quit." & vbCrLf & vbCrLf & "Generated name: " & generatedName
    newComputerName = InputBox(message, title)
    
    
    If newComputerName = "" Then
        Wscript.quit
    End If
    
    areYousure = MsgBox("Are you sure you want t0 add computer to domain with name:" & vbCrLf & vbCrLf & newComputerName, vbYesNo + vbQuestion,"Add computer to domain")
    
    If areYouSure = "7" Then
        MsgBox "Exiting script.",vbInformation
        Wscript.quit
    End If 
    
    Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\" & _
        strComputer & "rootcimv2:Win32_ComputerSystem.Name='" & _
            strComputer & "'")
    
    'Change OU here (Default is "OU=Computers,DC=домен,DC=домен")
    ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & "" & strUser, "OU=My Computers,OU=Computers,DC=domain,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
    
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")
    
    Set colComputers = objWMIService.ExecQuery _
        ("Select * from Win32_ComputerSystem")
    
    
    For Each objComputer in colComputers
        MsgBox "About to rename computer to: " & newComputername
            ErrCode = objComputer.Rename(newComputerName, strPassword, strUser)
        If ErrCode = 0 Then
            MsgBox "Computer renamed correctly."
        Else
            MsgBox "Eror changing computer name. Error code: " & ErrCode
        End If
    
    Next

    заменил 

    SetobjWMIService = GetObject ("winmgmts:""!\" & strComputer & "rootcimv2")

    на

    Set objWMIService = GetObject ("winmgmts:" & "!\\" & strComputer & "\root\cimv2")

      

    а то не хотел предлагать даже имя вводить...

    после ввода имени к компьютера и подтверждения выдает ошибку 0X8004100E, строка 40, символ 1.. что поправить



    • Изменено adomantit 18 апреля 2013 г. 5:59
    17 апреля 2013 г. 13:02