SkillPilotAI

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?

Output
where C:\Windows\System32:netdomwhere C:\Windows\System32:dfsdiag
Output
C:\> 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

netdom join: computer account + secure channel
  1. 1.PC01 is in a workgroup; admin runs netdom join to contoso.com

  2. 2.Join request reaches DC01 (192.168.10.10)

  3. 3.DC creates computer account PC01 in OU=Workstations

  4. 4.PC and DC exchange a shared secret (machine account password)

  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

Output
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

Output
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"
Output
netdom move mywksta /domain:mydomain /userd:mydomain\admin /passwordd:*netdom remove mywksta /domain:MyDomain /userd:MyDomain\admin /passwordd:*netdom renamecomputer MyServer /newname:MyNewServer
CommandWhat it doesKey options
addPre-creates a computer account in the domain/domain, /userd /passwordd:*, /ou, /dc, /server
joinJoins the computer to the domain/domain (FQDN), /ou, /usero, /readonly, /passwordm, /reboot
moveMoves a computer to a new domain, keeps SID history/userd (new), /usero (PC), /userf (old domain, disables old account)
removeRemoves the computer from the domain/domain, /userd, /usero, /force, /reboot
renamecomputerRenames 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

Output
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
  1. /add adds the new name as an alternate name.
  2. /makeprimary makes it the primary name.
  3. Reboot.
  4. /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

Output
netdom query /domain:NorthAmerica SERVERnetdom query /domain:<Domain> WORKSTATION | SERVER | DC | OU | PDC | FSMO | TRUSTnetdom query /domain:<Domain> TRUST /direct
ObjectLists
WORKSTATION / SERVER / DCWorkstations, servers, domain controllers
OUOUs where the user can add computers
PDCCurrent PDC emulator
FSMOAll FSMO role owners
TRUSTTrusts of the domain (/direct: only direct ones)

202.8 Secure channel: verify, reset, resetpwd

Broken secure channel and the fix
  1. 1.mywksta shares a machine account password with the DC

  2. 2.PC restored from an old snapshot: the secret no longer matches

  3. 3.netdom verify against DC01 fails: secure channel broken

  4. 4.netdom reset /Server:MyOtherDC rebuilds the channel

  5. 5.Login works again, no remove + rejoin needed

Output
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

One-way trust: NorthAmerica users reach a USA-Chicago file server
  1. 1.netdom trust USA-Chicago /domain:NorthAmerica /add

  2. 2.USA-Chicago = trusting domain, NorthAmerica = trusted domain

  3. 3./verify checks the trust's secure channel secrets: trust OK

  4. 4.NorthAmerica user gets a Kerberos ticket from its own DC

  5. 5.Ticket goes through the trust to USA-Chicago; the file server grants access

Trust direction is opposite to access direction

Output
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
OptionEffect
/add /remove /twowayCreate, remove, or make a two-way trust
/verify /reset /kerberosCheck or reset trust secrets, verify Kerberos across the trust
/realm /transitiveTrust with a non-Windows Kerberos realm
/quarantine:yesSID filtering: only SIDs of the directly trusted domain are accepted
/enablesidhistoryMigrated users can use SID history
/selectiveauth, /enabletgtdelegation, /authtargetvalidationTighten 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

DFS referral path
  1. 1.Client opens \\contoso.com\MyNamespace\folder1

  2. 2.Domain referral from the DC

  3. 3.Folder referral from the namespace server: fs1 (Site A), fs2 (Site B)

  4. 4.Client picks the target in its own site (\\fs1\share)

  5. 5.File opens; dfsdiag tests each of these steps

Output
dfsdiag /testdcs /domain:contoso.comdfsdiag /testdfsconfig /DFSroot:\\contoso.com\MyNamespacedfsdiag /testsites /machine:MyServerdfsdiag /testreferral /DFSpath:\\contoso.com\MyNamespace
TestWhat it checks
/testdcsDFS service and site-costed referrals on every DC
/testsitesSite association of a server or folder target (/recurse, /full)
/testdfsconfigNamespace server service and registry config
/testdfsintegrityNamespace metadata, ABE; /full also ACLs, registry vs AD DS
/testreferralWhole 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.