[PowerShell] Joining a domain14 Jun 2018
Recently my world has been centered more and more around Windows. Lately this is not a Bad Thing™. In fact, Windows Server Core and PowerShell have both come a LONG way. In the not so recent past, I wrote about how to set up Active Directory with PowerShell. In this post, I show you how to use PowerShell to join said domain.
The process that follows assumes you have:
- An Active Directory domain.
- A server to join to the domain.
- Optional: Said server is Windows Server Core
- A user account with access to said domain.
- A local user account on the server to be joined.
How to do it
To join the server to the domain, we will:
- Set DNS to use the Domain Controller
Get-NetAdapter -InferfaceIndex Set-DnsClientServerAddress -InterfaceIndex 2 ` -ServerAddresses ("10.127.16.100")
- Optional: Rename the computer
This can be done in two ways, either rename & reboot, or rename as part of the join. I have found the two reboot process to work more consistently.
Rename and reboot
# If you have more work to do, remove the -Reboot # from the Rename-Computer command and use: # Reboot-Computer -Force Rename-Computer -NewName "app-01" -Reboot
Rename at Join
Add-Computer -DomainName "codybunch.local" ` -NewName "app-01" ` -LocalCredential 'Administrator' ` -DomainCredential 'codybunch\Administrator' ` -Restart -Force
- Join the domain
Last, we join the domain.
Note: Only the -DomainName parameter is required. If the others are left unspecified, you will be prompted.
Add-Computer -DomainName "codybunch.local" ` -LocalCredential 'Administrator' ` -DomainCredential 'codybunch\Administrator' ` -Restart -Force