Domainjoin Windows 7

Domainjoin via add-computer command (Opsi Package)

This Script adds a client to a domain using powershell-tool 'add-computer' . Dieses Script fügt einen Client zu einer Domäne hinzu. Genutzt wird dazu das Powershell Tool Add-Computer.

You are able to choose the Domain via Product Property

by tobias

Properties

Create a OPSI Package with the following product properties:

  • dom - Domäne /domain
  • user - Benutzer zum hinzufügen in die Domäne / User with add-domain-rights
  • password - Passwort des Domänenbenutzers / password of domainadmin

join.ins

[INITIAL]
;Message = "Rechner wird zur Domäne hinzugefügt!"
Message = "Join computer to the domain!"
 
[Actions]
DefVar $dom$
DefVar $user$
DefVar $password$
set $dom$ = GetProductProperty("dom", " ")
set $user$ = GetProductProperty("user", " ")
set $password$ = GetProductProperty("password", " ")
PatchTextFile_Create_powershell %scriptpath%\join.ps1
ShellBatch_JoinDom
 
 
[PatchTextFile_Create_powershell]
AddLine  "$secpasswd = ConvertTo-SecureString '$password$' -AsPlainText -Force"
AddLine  '$mycreds = New-Object System.Management.Automation.PSCredential ("$user$", $secpasswd)'
AddLine  'Add-Computer -DomainName "$dom$" -credential $mycreds'
SaveToFile "c:\joinpatched.ps1"
 
[ShellBatch_JoinDom]
set-executionpolicy RemoteSigned
powershell c:\joinpatched.ps1
del c:\joinpatched.ps1



Domainjoin with an opsi-package

This Script will show you how to make a Domainjoin in Windows7 with a selfmade opsi-product. I choose this way because not every auto-installed Client must be a member of the Domain and you are more flexible by installing the Clients.

Script by Mike1987

  • Tested with opsi 4.0.1
  • Tested with opsi-winst 4.11.1.6
  • Tested with win7-x64 4.0.1-5 (Windows7-x64 Professional)

THIS PRODUCT IS ABLE TO BE USED IN WINDOWS 7 32-Bit AND 64-Bit ARCHITECTURES!!!

First of all you have to create a new opsi localboot product (description in Details in the opsi-manual) In this example the name of the opsi-prodcut is windows7-domainjoin

Content of setup.ins

[Initial]
Message= Windows7-Domainjoin
SetLogLevel=6
ExitOnError=false
ScriptErrorMessages=true
TraceMode=off
 
if FileExists64("C:\Windows\cmd64.exe")  
 
                Registry_install /64Bit 
                DosBatch_1
        else
                Registry_install /32Bit
                DosBatch_1
endif
 
[Registry_install]
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
set "AutoAdminLogon" = "1"
set "DefaultUsername" = "Administrator" 
set "DefaultPassword" = "password"
 
[DosBatch_1]
%scriptpath%\join.cmd

Content of join.cmd

copy "\\opsiserver\opsi_workbench\windows7-domainjoin\CLIENT_DATA\auto.reg" "C:\tmp\"
copy "\\opsiserver\opsi_workbench\windows7-domainjoin\CLIENT_DATA\join.vbs" "C:\tmp\"
copy "\\opsiserver\opsi_workbench\windows7-domainjoin\CLIENT_DATA\domainjoin.reg" "C:\Windows\System32\"
C:\Windows\system32\regedit.exe /S "C:\Windows\system32\domainjoin.reg"
shutdown /r /f /t 0

Content of join.vbs

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

strDomain = "DOMAINNAME"       ' Windowsdomain
strPassword = "DOMAINADMIN"    ' Password
strUser = "ADMINPASSWORD"      ' Domainadmin

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)

Set WSHShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "shutdown.exe -r -t 0"

Wscript.Quit

Content of domainjoin.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\LanmanWorkstation\Parameters]
"ServiceDll"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,\
  00,74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,\
  77,00,6b,00,73,00,73,00,76,00,63,00,2e,00,64,00,6c,00,6c,00,00,00
"ServiceDllUnloadOnStop"=dword:00000001
"EnablePlainTextPassword"=dword:00000000
"EnableSecuritySignature"=dword:00000001
"RequireSecuritySignature"=dword:00000000
"OtherDomains"=hex(7):00,00
"DomainCompatibilityMode"=dword:00000001
"DNSNameResolutionRequired"=dword:00000000

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce]
@="C:\\tmp\\join.vbs"

Content of auto.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
"AutoAdminLogon"="1"
"DefaultUsername"="Administrator"
"DefaultPassword"="password"

All these files (a total of 5) have to be copied to the /<PATH OF YOUR SELFMADE PRODUCTS>/windows7-domainjoin/CLIENT_DATA/ directory.

The build the product with opsi-makeproducfile an install it with opsi-package-manager -i windows7-domainjoin_1.0-1.opsi



Domainjoin with a Samba PDC

by chewbacca

tested by: Thomas_H 2011/11/21 14:31

Edit the /opt/pcbin/install/win7/custom/unattend.xml (or /opt/pcbin/install/win7-x64/custom/unattend.xml):

<component name="Microsoft-Windows-UnattendedJoin" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.c
     <Identification>
           <Credentials>
                 <Domain>mynet</Domain>
                 <Password>secret</Password>
                 <Username>Admin</Username>
           </Credentials>
           <DebugJoin>false</DebugJoin>
           <JoinDomain>meinnet</JoinDomain>
           <UnsecureJoin>false</UnsecureJoin>
     </Identification>
</component>

Domain means: the domain the client should be included
Password means: the password of the domainadmin, the account, which is allowed to include clients to the domain.
Username means: the name of the domainadmin.

Beginners please note: if the domainadmin's name (especially in a Samba-Domain) is “DomJoin”, so please enter THIS name, not the name of the admin (normally “Admin) of the client.

Create a file named “join.vbs”:

join.vbs

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
 
strDomain = "Windowsdomain" ' hier die Windowsdomain
strPassword = "very secret" ' very secret
strUser = "Domainadmin"  ' Domainadmin
 
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)
 
Set WSHShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "shutdown.exe -r -f -t 3"
 
set shell = WScript.CreateObject("WScript.Shell")
windir = shell.ExpandEnvironmentStrings("%windir%")
 
set filesys = CreateObject ("Scripting.FileSystemObject")
set tempFile = filesys.Getfile(windir & "\system32\join.vbs")
tempfile.Delete
 
Wscript.Quit      

and copy it to /opt/pcbin/install/win7/opsi.

Create a file name “default.reg”

default.reg

Windows Registry Editor Version 5.00
 
;Insert Samba Patch
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\LanmanWorkstation\Parameters]
"DomainCompatibilityMode"=dword:00000001
"DNSNameResolutionRequired"=dword:00000000
 
;join Domain at first start
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce]
"firstrun"="wscript.exe \"join.vbs\""

and copy it to /opt/pcbin/install/win7/opsi.

Create a file named “21_reg.cmd”

21_reg.cmd

rem --- Win7samba Patch and Join Script
echo [%date% %time%] copy -s "%script_drive%\opsi\join.vbs" "%SystemRoot%\System32\join.vbs"
copy "%script_drive%\opsi\join.vbs" "%SystemRoot%\System32\join.vbs"
echo [%date% %time%] Executing: regedit /s "%script_drive%\opsi\default.reg"
regedit /s "%script_drive%\opsi\default.reg"

and copy it to /opt/pcbin/install/win7/opsi/postinst.d

Set the rights of all three files to user opsiconfd:pcpatch



QR Code
QR Code userspace:windows7 (generated for current page)