Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Anyone have experience of using the JoinDomainOrWorkgroup Method of the Win32_ComputerSystem Class?

I want to write a powershell script to join a machine to a domain. There may be an existing computer account for the machine, and if so I want to delete it and rejoin to the domain.

I've already scripted the "search and destroy" part that will delete the computer account if it exists, but just noticed the FJoinOptions switches on Technet. Trouble is - they're a bit ambiguous.

Does 4 (0x4) Deletes an account when a domain exists. mean it will delete the computer account if it already exists on the domain?

Also, can you specify the computername you want to join the machine under with this method, or should you do a rename and then join the domain.



NB - I've been using the guide at - not sure if there's a better resource out there.

share|improve this question
up vote 1 down vote accepted

It looks like this WMI method is just a wrapper around NetJoinDomain, and you'll notice that the 0x04 option isn't documented there, so I don't think it's applicable.

Looking at LMJoin.h in the Platform SDK and the docs for NetUnjoinDomain it says for NETSETUP_ACCT_DELETE 0x04 "the account is disabled when the unjoin occurs" - so it looks like the documentation team got over-zealous and it's only really applicable for unjoin operations.

For more info see the Directory Service Functions docs on MSDN.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.