Saturday, January 28, 2017

Adding a Windows Nano server to the domain

In my previous article, I created a Nano server image. This one is about adding the Nano server to a domain. Adding Nano servers to a domain isn't a pretty little single cmdlet like many others are, but consists of a list of things to do:

  • Configure DNS on the Nano server
  • Create what's called a blob file on a DC (or a machine that is joined to the domain, and a user that has rights to add a computer to the domain or as a Domain admin user)
  • Copy the file over to the Nano server
  • Use the blob file to add the server to the domain
  • Reboot
I've found the following code on site, with an ingenious way to copy the blob file over. If you have the Storage package installed, you can of course just copy it using a share like \\nanosrv1\c$

#Set dns for Nano server
netsh interface ip set dnsservers name="Ethernet" static primary

#Create domain blob file
djoin.exe /provision /domain /machine nanosrv1 /savefile c:\temp\odjblob

#get file over to nano server, needs trustedhosts first
Set-Item WSMan:\localhost\Client\TrustedHosts  "" -Concatenate

#trick from
#to copy the blob over to the target server
$filePath = 'c:\temp\odjblob'
$fileContents = Get-Content -Path $filePath -Encoding Unicode
$session = New-PSSession -ComputerName -Credential nanosrv1\username
Invoke-Command -Session $session -ArgumentList @($filePath,$fileContents) -ScriptBlock {
    New-Item -ItemType directory -Path c:\temp
    Set-Content -Path $filePath -Value $data -Encoding Unicode

#Now add the nano to the domain with the blobfile
djoin /requestodj /loadfile c:\temp\odjblob /windowspath c:\windows /localos
shutdown /r

It is a bit convoluted, but once you get the hang of it, it is doable..

No comments:

Post a Comment