Cody Bunch Some Random IT Guy - OpenStack, DevOps, Cloud, Things

[PowerShell] Joining a domain

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.

Getting Started

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:

  1. Set DNS to use the Domain Controller
Get-NetAdapter -InferfaceIndex
Set-DnsClientServerAddress -InterfaceIndex 2 `
    -ServerAddresses ("10.127.16.100")
  1. 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
  1. 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