Set the PC Name and Join Domain Automatically

The KACE K2000 has a post installation task that can rename a computer and join it to a Windows Domain.  This simple tool works.  It allows me to name the PC using a tool created by David Clarke called WSNAME.

Configure Sysprep Unattend.xml to Autoname the PC

When you create your unattend.xml file to use with Sysprep you set the Step 4, Specialize, Windows Shell Setup to have the Computer Name = * which tells Sysprep to generate a random name for the PC.  The WAIK configuration looks like this:

WAIK Answer File

Post Installation Task to Set the PC Name and Join the Domain

Download and extract the tool.  You get a batch file and a sub directory.  The batch file is called start_x64.bat and its task is to set the wsname up as a Run Once registry setting and reboot the computer.

@echo Rename and Join a Windows 7 x64 computer to a domain

xcopy /S /E /I source c:\source

reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v V1 /t REG_SZ /d "CMD /C \"C:\source\1_wsname_x64.bat\"" /f

shutdown -r -t 10

The sub directory contains two batch files, the wsname.exe and the join_domain.vbs.  You need to add a namedb.dat file which is just a text file that contains the computer names and an identifier.

You can use the MAC address or the BIOS Serial number.  If you look at David Clarke’s site there are other commands that can be used too.  I want to use my Dell Express Service Code which is my system serial number.  The $SERIALNUM variable picks the ESC directly from Bios.  I then use it as the key to find my actual computer name.  So my namedb.dat file contains:

SN1 = PC001
SN2 = PC002
.
.
.
SNX = PCXXX

and then the 1_wsname_x64.bat file contains:

c:\source\wsname.exe /RDF:c:\source\namedb.dat /DFK:$SERIALNUM /Logfile:C:\wsname.txt

reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v V1 /t REG_SZ /d "CMD /C \"C:\source\2_JoinDomain_x64.bat\"" /f

shutdown -r -t 300

Name the PC then add the next task to the Windows Run Once and reboot.

The 2_JoinDomain_x64.bat file is then launched and it runs the JoinDomain.vbs script that actually joins the domain.  It then cleans the registry up from the Sysprep Auto Login and removes the source directory.  Lastly another reboot.  The 2_JoinDomain_x64.bat looks like this:

REM Join a Windows 7 x64 computer to the domain

REM ***** Join_Domain.vbs <domain> <DomainUser> <password> <Default domain DNS Server IP> *****>

C:\source\Join_Domain.vbs Domain Admin password 192.168.1.1

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 0 /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d <NULL> /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d <NULL> /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v V1 /t REG_SZ /d "CMD /C \"rd /s /q C:\source\""

shutdown -r -t 300

All of this is then sent to a compressed file and added as a post installation task in the K2000.

NameJoinDomain Task

Then in the Deployment System Image Details this tasks is added to the Run Postinstallation Tasks as the first task of the Reboot (Exit Boot Environment) stage.

NameJoinDomain-SystemImageDetail

When the image is deployed the K2000 injects this into the PC’s hard drive and runs it.  The machine will boot and run Sysprep, then reboot and run the NameJoinDomain task.  When it is done the PC will be named and in the domain. ready for a user to log in.