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 petri.com 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 10.0.0.4 primary


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


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


#trick from https://www.petri.com/join-windows-server-2016-nano-domain
#to copy the blob over to the target server
$filePath = 'c:\temp\odjblob'
$fileContents = Get-Content -Path $filePath -Encoding Unicode
$session = New-PSSession -ComputerName 10.0.0.5 -Credential nanosrv1\username
Invoke-Command -Session $session -ArgumentList @($filePath,$fileContents) -ScriptBlock {
    param($filePath,$data)
    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