Admin Power Level: Intermediate Chapter 11: Manage People, Computers, and Names

AD computers: join, read, and disconnect

Computers join a domain as computer objects. Add-Computer joins a computer, and the domain keeps a trust relationship with it, which can break if the computer is offline too long or is reset badly.

Lesson 2 of 6 in Chapter 11: Manage People, Computers, and Names. Previous step in this path: AD users: create, read, change, and remove. 3 learning objectives, 7 examples, and a knowledge check.

Start: what you will learn

Computers join a domain as computer objects. Add-Computer joins a computer, and the domain keeps a trust relationship with it, which can break if the computer is offline too long or is reset badly.

Learning objectives

  • Explain what joining a domain means
  • Join a computer with Add-Computer
  • Explain the disconnected trust problem and its fix

Concept in simple words

What it is: AD computer management means joining a computer to a domain, reading its computer object in Active Directory, and fixing the trust between the computer and the domain when that trust breaks.

Why it works

Why it works this way: When a computer joins a domain, it gets a computer object in the directory, and the computer and the domain controllers, which are the servers that answer logon and directory requests, agree to trust each other. That trust lets domain users log on to the computer, and it is kept alive by a computer account password that the computer renews quietly in the background.

Think of it like this

Think of it like this: Joining a domain is like a new member joining a club and getting a membership card. The club trusts the card, the member trusts the club, and if the card stops matching the club records, the door will not open, even if the person at the door is genuine.

How it works, step by step

How it works, step by step: First, make sure the computer can resolve the domain by DNS, which is the naming system that turns names into addresses, because a join fails before it starts if DNS cannot find the domain. Then run Add-Computer -DomainName example.local, give domain credentials, which are a username and password with permission to join computers, when asked, and restart when told to.

Next, check the result by reading the computer object, for example with Get-ADComputer, and confirm it is enabled. This work needs a proper server environment, the Active Directory module where the AD cmdlets are used, and the right permissions, so do not treat a domain join as a casual task on a normal workstation.

Let us walk through an example: In Add-Computer -DomainName "example.local" -Restart, -DomainName names the domain to join, and -Restart reboots at once so the change takes effect. Look for a message that the computer joined the domain, and if the join fails, check DNS first, then credentials, because a DNS failure looks a lot like a password failure at first glance.

When to use it

When to use it, and when not to: Use Add-Computer when a computer should belong to a domain you are allowed to administer, and use Get-ADComputer when you need to check a computer object. Do not rejoin a computer, or reset its account, just because a logon failed once, without understanding the cause, and do not keep retrying the same password when the real problem is a broken trust relationship, because that trust problem needs a clean rejoin or a reset of the computer account, not another password attempt.

Start from zero, with workgroup versus domain: A workgroup computer trusts only itself. Each computer keeps its own local accounts, and a user on one computer means nothing on the next computer. A domain computer trusts the domain. It checks logons against domain controllers, it follows domain policy, and a domain user can log on to any domain computer they are allowed to use. Joining a domain moves a computer from the first world into the second, and that move changes where logons are checked, so it must never be done casually.

What happens behind the join: When you run Add-Computer, PowerShell contacts a domain controller, proves your join credentials, and creates a computer object in the directory if one does not already exist. The computer and the domain then share a computer account password, which the computer renews quietly in the background. After a restart, the computer presents that shared secret when a domain user logs on, and the domain controller checks it. If the secret on the computer no longer matches the secret in the directory, the controller refuses the logon, even when the user typed the right user password, because the computer itself is no longer trusted.

Why it works

Why DNS comes first: Before any trust can be checked, the computer must find a domain controller, and it finds one by asking DNS. In a domain, DNS holds service records that point to domain controllers, so a client asks DNS where the domain service lives, and DNS answers with a controller address. If the computer points at a DNS server that knows nothing about the domain, the join fails at the very first step, and the error can look like a wrong password. That is why the fix order is DNS first, then credentials, then the computer object, and only then a trust repair.

Let us walk through a join into the right OU, part by part: In Add-Computer -DomainName "example.local" -OUPath "OU=Workstations,DC=example,DC=local" -Credential (Get-Credential) -Restart, -DomainName names the domain, -OUPath names the OU where the new computer object should live, -Credential (Get-Credential) asks you for a join account and password at a prompt instead of typing the password in the command, and -Restart reboots at once so the change takes effect. Without -OUPath, the new object lands in the default Computers container, and policy aimed at your workstation OU may never reach it, so check where the object landed after the join.

Precreating a computer object is not a join: New-ADComputer creates a computer object in the directory, but it does not join any real computer to the domain. That distinction matters. Precreation is useful when you want the object to exist in a chosen OU before the real computer joins, but the real computer still has to run Add-Computer before domain users can log on to it. If you precreate and then forget the join step, you will see a neat object in the directory and a computer that still behaves like a workgroup computer.

Let us walk through a read only trust check: Test-ComputerSecureChannel with no extra parameters tests the secure channel between the local computer and its domain, and it answers True when the channel works and False when it does not. This is a read only check, it changes nothing, and it is the right first step when domain logons fail. A True answer tells you to look elsewhere, such as the user account or the user password. A False answer tells you the computer trust is the problem, not the user.

Let us walk through a trust repair, with a warning: Test-ComputerSecureChannel -Repair -Credential (Get-Credential) rebuilds the secure channel, and -Credential asks for an account with permission to do that repair. Warning: this changes the trust between this computer and the domain, so run it only on the affected computer, only in your own lab domain, with permission, and only after the simple test has returned False. After a repair, test again with Test-ComputerSecureChannel, and restart if logons still fail, because a repaired channel sometimes needs a fresh logon to show its effect.

A second repair route, and when to use it: Reset-ComputerMachinePassword -Server "DC01" -Credential (Get-Credential) resets the machine account password for the local computer, using the named domain controller. Warning: this also changes shared trust material, so use it only when the repair above has not worked, only in your own lab domain, with permission, and never as a first guess after one failed logon. After either repair, verify with the simple test, because a repair you never verify is only a hope, not a fix.

Leaving a domain is also a change, not a cleanup: Remove-Computer takes a computer out of a domain and back to a workgroup, and after that, domain users can no longer log on to it with domain accounts. Warning: do not remove a computer from a domain to fix a small problem, and never remove a computer you do not own or are not allowed to administer, because the computer will need a local administrator logon afterwards, and domain policy and domain access will be gone until it is joined again.

A calm order for trust trouble: First, check DNS and the computer object with Get-ADComputer, and confirm the object is enabled. Second, run the simple secure channel test. Third, repair only if the test says False. Fourth, verify with the test again, and restart before you declare the fix a failure. Jumping straight to a rejoin skips the diagnosis, and a rejoin of a computer with a duplicate name or a stale object can leave two objects fighting over one name.

Worked examples

Read each example in order. Each one explains its parts, then shows what to look for in the output.

Syntax

Syntax
Add-Computer -DomainName <Domain> -Credential <Credential>

Example 1

Joins the domain and restarts. You will be asked for domain credentials with join permission.

Example 1
Add-Computer -DomainName "example.local" -Restart

Illustrative output: Computer joined to example.local. Restarting.

Example 2

Lists domain computer objects whose names start with srv, with their enabled state.

Example 2
Get-ADComputer -Filter { Name -like "srv*" } | Select-Object Name, Enabled

Illustrative output: Name Enabled ---- ------- srv1 True

Example 3

-Identity srv1 reads one computer object by name, which is the safest way to check a single computer. Select-Object Name, DNSHostName, Enabled shows the computer name, its full DNS host name, which is the name DNS uses for it, and whether the account is enabled. This read only check needs the Active Directory module and domain read permission, and it changes nothing, so it is a good first step before any fix.

Example 3
Get-ADComputer -Identity srv1 | Select-Object Name, DNSHostName, Enabled

Illustrative output: Name DNSHostName Enabled ---- ---------- ------- srv1 srv1.example.local True

Example 4

Warning: this joins the computer to a domain, so use it only on a computer you are allowed to administer, in your own lab domain. -OUPath places the computer object in the Workstations OU, and -Credential asks for the join account at a prompt.

Example 4
Add-Computer -DomainName "example.local" -OUPath "OU=Workstations,DC=example,DC=local" -Credential (Get-Credential) -Restart

Illustrative output: Computer joined to example.local. Restarting.

Example 5

A read only trust check. True means the secure channel works. False means the computer trust is broken, even if the user password is correct.

Example 5
Test-ComputerSecureChannel

Illustrative output: True

Example 6

Warning: this rebuilds the secure channel, so run it only on the affected computer, in your own lab domain, with permission, and only after the simple test has returned False. Verify afterwards with Test-ComputerSecureChannel.

Example 6
Test-ComputerSecureChannel -Repair -Credential (Get-Credential)

Illustrative output: True

Example 7

Warning: this creates a computer object in the directory, in your own lab domain, with permission. It does not join any real computer. The real computer still needs Add-Computer before domain logons work on it.

Example 7
New-ADComputer -Name "srv2" -Path "OU=Servers,DC=example,DC=local" -Enabled $true

Illustrative output: Computer object srv2 created.

Nothing on this page executes PowerShell code. The outputs above are illustrative only.

Common mistakes and troubleshooting

Read these before you try the examples, so you can spot the same problems in your own work.

  • Joining a domain when DNS cannot resolve it, then blaming the credentials. Check DNS first.
  • Resetting a computer account without understanding the trust problem, which can make logons worse. Rejoin cleanly instead.
  • Joining a computer to a domain while it points at the wrong DNS server, then blaming the domain credentials, when the real fix is to point the computer at a domain DNS server first and try again.
  • Joining without a restart, then testing a domain logon and concluding the join failed, when the change simply has not taken effect yet.
  • Resetting the computer account on the server side alone and expecting the local computer to work at once, when the local copy of the shared secret still has to be repaired from the computer itself.
  • Joining a computer under a name that already exists in the directory, then getting a clash, when a Get-ADComputer check first would have shown the existing object.

Knowledge check

Knowledge check

What breaks when a computer loses trust with its domain?

Pick one answer. Feedback appears right away, and you can try again.

Remember this and next step

Remember this: A domain join is a trust agreement built on DNS and permissions, and when logons fail with a correct password, think trust first, check DNS and the computer object, and fix the trust cleanly.

Next step: Forest, domain, and domain controllers