Deploy a Domain Joined Nanoserver with DeployImage Module–Part 3


Yesterday we looked at configuring a static ip address on Nano Server through the use of SetupComplete.cmd but today we’ll add in the next piece, joining a Domain.

Again, we must keep in mind two things, the early age of Nano and the fact it’s still being developed.   So we’re missing some pieces.

There is first off no directly way through the Emergency console to add this to a Domain.  In fact there is no command that creates the account in Active Directory. 

Well that’s not EXACTLY true.    Nano Server supports an Offline Domain join.

To create an offline Domain join requires three steps

  • Create the offline Join file
  • Copy the file to the workstation/server
  • Execute an offline Join with the provided file

The other method involves injecting the text from the Domain Join file into an Unattend.xml, but I haven’t have any luck with the documented process on Technet.

In this scenario we would like to join a workstation to a Domain with the following settings.

Domain     : Contoso

Computer : Contoso-Nano1

Filename   : domainjoin.djoin

On a computer which has the RSAT tools for Active Directory we need to run the Djoin.exe Command to create the file needed.   We can run this manually for the stated configuration in the following manner.

Djoin.exe /Provision /Domain Contoso /Machine Contoso-Nano1 /Savefile domainjoin.djoin

We can also run this in PowerShell by providing objects to store the information.

$Domain=’Contoso’
$Computername=’Contoso-Nano1’
$Filename=’domainjoin.djoin’
Djoin.exe /Provision /Domain $Domain /Machine $Computername /Savefile $Filename

We then copy the file over to the destination file system in some manner.    Ideally we’ll put the file into maybe the same folder as the Setup\Scripts folder.

On the destination system we would run the follow command directly to join this system to a Domain.   The nice part is you do NOT need to be on the network to make this work once the file is the destination system.

After all, this is an offline Domain join.

Djoin.exe /RequestODJ /loadfile C:\Windows\setup\scripts\domainjoin.djoin /windowspath c:\windows /localos

Now to make this work we’ll be using the same process as yesterday with SetupComplete.cmd and a HereString only we’ll be appending it to the NetSh.exe content.

$Filename=’C:\Windows\setup\scripts\domainjoin.djoin’

$SetupCompleteCMD=@”
netsh interface ipv4 set address Name=”Ethernet” static $IPAddress $Subnet $Gateway
netsh dns set dnsservers name=”Ethernet” source=static address=$DNS
djoin /requestodj /loadfile $Filename /windowspath c:\windows /localos
shutdown -f -r -t 0
“@

# Create the new one
#
Remove-Item -Path SetupComplete.cmd -Force -ErrorAction SilentlyContinue
New-Item -ItemType File -Name SetupComplete.cmd -Force | Out-Null
Add-content SetupComplete.cmd -Value $SetupCompleteCMD

Now with the Unattend.xml and the Setupcomplete.cmd in the appropriate locations if we were to inject the boot code the Nano Server will boot up, named as it should be, IP address assigned and joined to the appropriate Domain.

If you’d like a deeper look at the script performing this in action just access DeployImage from www.powershellgallery.com .

Once you install the Module (It has been tested under Windows 10 with the Windows 10 ADK installed) you can execute the following Cmdlet to get the sample scripts.

Copy-DeployImageSample

Just open up the script called DeployNanoServerVHDDomain.ps1 and have a field day.

If you have any comments or feedback please feel free to reach out at sean at powershell dot ca or submit comments, critique or pull requests on the Github source.

Cheers!

Sean
The EnergizedTech

Follow

Get every new post delivered to your Inbox.

Join 3,718 other followers