netdom and dfsdiag
netdom manages Active Directory computer accounts (add, join, move, rename), secure channels and trusts from the command line; dfsdiag diagnoses DFS Namespaces (DCs, sites, configuration, referrals). Both are everyday tools for fixing domain-join and file-share problems.
202.1 Why is it used?
- Join, move, rename or remove computers in a domain from a script, without the GUI.
- Fix the "trust relationship failed" error by verifying and resetting the secure channel.
- Create, verify and harden trusts between domains (SID filtering, selective auth).
- Find why a DFS client gets a wrong or far-away folder target.
- Available on a Windows Server with the AD DS or DFS role, or on a client after installing RSAT; no Linux/macOS version.
202.2 Are the tools on this PC?
where C:\Windows\System32:netdomwhere C:\Windows\System32:dfsdiagC:\> where C:\Windows\System32:netdomINFO: Could not find files for the given pattern(s).C:\> where C:\Windows\System32:dfsdiag- The office PC is domain-joined, so only this safe check was run.
- No file found for either tool because RSAT is not installed; everything else comes from the docs.
202.3 How netdom join works
- Step 1
1.PC01 is in a workgroup; admin runs netdom join to contoso.com
- Step 2
2.Join request reaches DC01 (192.168.10.10)
- Step 3
3.DC creates computer account PC01 in OU=Workstations
- Step 4
4.PC and DC exchange a shared secret (machine account password)
- Step 5
5.Secure channel is built: PC01 is now a domain member
The secure channel lets the domain authenticate this PC
202.4 netdom general options
netdom help list of commandsnetdom help <command> help for one commandnetdom <command> /? same help (join /?)/verbose each transaction: ok / fail/reboot[:sec] restart afterwards (20 s default) netdom [ ADD | COMPUTERNAME | HELP | JOIN | MOVE | MOVENT4BDC | QUERY | REMOVE | RENAMECOMPUTER | RESET | RESETPWD | TRUST | VERIFY ]202.5 add, join, move, remove, renamecomputer
netdom add mywksta /domain:reskita /userd:domainadmin /passwordd:*netdom add Srv01 /domain:reskita /OU:"OU=Servers,DC=reskita,DC=com" /userd:domainadmin /passwordd:* netdom join mywksta /domain:contoso.com /userd:user01 /passwordd:*netdom join mywksta /domain:devgroup.contoso.com /OU:"OU=Workstations,OU=Dsys,DC=devgroup,DC=contoso,DC=com"netdom move mywksta /domain:mydomain /userd:mydomain\admin /passwordd:*netdom remove mywksta /domain:MyDomain /userd:MyDomain\admin /passwordd:*netdom renamecomputer MyServer /newname:MyNewServer| Command | What it does | Key options |
|---|---|---|
| add | Pre-creates a computer account in the domain | /domain, /userd /passwordd:*, /ou, /dc, /server |
| join | Joins the computer to the domain | /domain (FQDN), /ou, /usero, /readonly, /passwordm, /reboot |
| move | Moves a computer to a new domain, keeps SID history | /userd (new), /usero (PC), /userf (old domain, disables old account) |
| remove | Removes the computer from the domain | /domain, /userd, /usero, /force, /reboot |
| renamecomputer | Renames a member PC and its AD account together | /newname, /force, /reboot (members only, not DCs) |
- /passwordd:* asks for the password at a prompt instead of typing it on the command line.
- Without /ou the account goes to the Computers container; /ou cannot be combined with /dc or /server in add.
- /readonly joins using a pre-created account without writing to a DC (RODC scenario).
- Know the local admin password before remove: domain logins stop working afterwards.
202.6 Safe DC rename: netdom computername
netdom computername mydc.mydomain.com /add:altDCname.mydomain.comnetdom computername mydc.mydomain.com /makeprimary:altdcname.mydomain.com(reboot)netdom computername mydc.mydomain.com /remove:<old FQDN>netdom computername mydc.mydomain.com /enumerate:ALLNAMES- /add adds the new name as an alternate name.
- /makeprimary makes it the primary name.
- Reboot.
- /remove deletes the old name; /verify checks every name has a DNS record and an SPN.
movent4bdc (rename an NT 4.0 BDC) is legacy; just remember it as history.
202.7 netdom query
netdom query /domain:NorthAmerica SERVERnetdom query /domain:<Domain> WORKSTATION | SERVER | DC | OU | PDC | FSMO | TRUSTnetdom query /domain:<Domain> TRUST /direct| Object | Lists |
|---|---|
| WORKSTATION / SERVER / DC | Workstations, servers, domain controllers |
| OU | OUs where the user can add computers |
| PDC | Current PDC emulator |
| FSMO | All FSMO role owners |
| TRUST | Trusts of the domain (/direct: only direct ones) |
202.8 Secure channel: verify, reset, resetpwd
- Step 1
1.mywksta shares a machine account password with the DC
- Step 2
2.PC restored from an old snapshot: the secret no longer matches
- Step 3
3.netdom verify against DC01 fails: secure channel broken
- Step 4
4.netdom reset /Server:MyOtherDC rebuilds the channel
- Step 5
5.Login works again, no remove + rejoin needed
netdom verify mywksta /domain:devgroup.contoso.comnetdom reset mywksta /domain:MyDomain.contoso.com /Server:MyOtherDCnetdom resetpwd /server:MyDC /userd:admin /passwordd:*- verify checks the channel, reset rebuilds it (optionally with a specific DC via /server).
- resetpwd resets the DC's own machine account password; run it locally on the DC.
- /securepasswordprompt shows a secure popup (smartcard) in all three.
202.9 netdom trust
- Step 1
1.netdom trust USA-Chicago /domain:NorthAmerica /add
- Step 2
2.USA-Chicago = trusting domain, NorthAmerica = trusted domain
- Step 3
3./verify checks the trust's secure channel secrets: trust OK
- Step 4
4.NorthAmerica user gets a Kerberos ticket from its own DC
- Step 5
5.Ticket goes through the trust to USA-Chicago; the file server grants access
Trust direction is opposite to access direction
netdom trust USA-Chicago /domain:NorthAmerica /addnetdom trust USA-Chicago /domain:NorthAmerica /verifynetdom trust <trusting> /domain:<trusted> /twoway | /kerberos | /reset | /removenetdom trust <trusting> /domain:<trusted> /quarantine:yesnetdom trust <trusting> /domain:<trusted> /enablesidhistory| Option | Effect |
|---|---|
| /add /remove /twoway | Create, remove, or make a two-way trust |
| /verify /reset /kerberos | Check or reset trust secrets, verify Kerberos across the trust |
| /realm /transitive | Trust with a non-Windows Kerberos realm |
| /quarantine:yes | SID filtering: only SIDs of the directly trusted domain are accepted |
| /enablesidhistory | Migrated users can use SID history |
| /selectiveauth, /enabletgtdelegation, /authtargetvalidation | Tighten the trust |
- netdom trust cannot create a forest trust between two AD DS forests; use AD Domains and Trusts or PowerShell.
- Most trust options without a value just show the current state.
202.10 DFS Namespaces and dfsdiag
- Step 1
1.Client opens \\contoso.com\MyNamespace\folder1
- Step 2
2.Domain referral from the DC
- Step 3
3.Folder referral from the namespace server: fs1 (Site A), fs2 (Site B)
- Step 4
4.Client picks the target in its own site (\\fs1\share)
- Step 5
5.File opens; dfsdiag tests each of these steps
dfsdiag /testdcs /domain:contoso.comdfsdiag /testdfsconfig /DFSroot:\\contoso.com\MyNamespacedfsdiag /testsites /machine:MyServerdfsdiag /testreferral /DFSpath:\\contoso.com\MyNamespace| Test | What it checks |
|---|---|
| /testdcs | DFS service and site-costed referrals on every DC |
| /testsites | Site association of a server or folder target (/recurse, /full) |
| /testdfsconfig | Namespace server service and registry config |
| /testdfsintegrity | Namespace metadata, ABE; /full also ACLs, registry vs AD DS |
| /testreferral | Whole referral path end to end; SYSvol/NETLOGON TTL 900 s |
The Microsoft Learn examples have no sample output, so only the syntax is shown.
202.11 Common mistakes
- Renaming a DC with renamecomputer: it is for workstations and member servers only; use computername.
- Removing and rejoining a PC for a trust error: netdom verify then netdom reset is enough.
- Typing passwords on the command line instead of /passwordd:*.
- Expecting netdom trust to build a forest trust.
202.12 Interview tips
- netdom = AD command-line tool: join, move, rename computers; query DCs/FSMO; verify/reset secure channels and trusts.
- Trust relationship error at login: netdom verify first, then netdom reset /Server:<DC>.
- DC rename: computername /add -> /makeprimary -> reboot -> /remove.
- dfsdiag diagnoses DFS Namespaces: DCs, sites, config/integrity and referrals.